Home / Class/ Machine Class — tailwindcss Architecture

Machine Class — tailwindcss Architecture

Architecture documentation for the Machine class in machine.rs from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  8f9ba79f_1590_e3c4_8f56_fc6df784db96["Machine"]
  4c43dba8_bb08_844b_c3a0_aaf9e55dffb8["machine.rs"]
  8f9ba79f_1590_e3c4_8f56_fc6df784db96 -->|defined in| 4c43dba8_bb08_844b_c3a0_aaf9e55dffb8

Relationship Graph

Source Code

crates/oxide/src/extractor/machine.rs lines 33–161

pub trait Machine: Sized + Default {
    fn reset(&mut self);
    fn next(&mut self, cursor: &mut cursor::Cursor<'_>) -> MachineState;

    /// Reset the state machine, and mark the machine as [MachineState::Idle].
    #[inline(always)]
    fn restart(&mut self) -> MachineState {
        self.reset();
        MachineState::Idle
    }

    /// Reset the state machine, and mark the machine as [MachineState::Done(…)].
    #[inline(always)]
    fn done(&mut self, start: usize, cursor: &cursor::Cursor<'_>) -> MachineState {
        self.reset();
        MachineState::Done(Span::new(start, cursor.pos))
    }

    #[cfg(test)]
    fn test_throughput(iterations: usize, input: &str) {
        use crate::throughput::Throughput;
        use std::hint::black_box;

        let input = input.as_bytes();
        let len = input.len();

        let throughput = Throughput::compute(iterations, len, || {
            let mut machine = Self::default();
            let mut cursor = cursor::Cursor::new(input);

            while cursor.pos < len {
                _ = black_box(machine.next(&mut cursor));

                cursor.advance();
            }
        });
        eprintln!(
            "{}: Throughput: {}",
            std::any::type_name::<Self>(),
            throughput
        );
    }

    #[cfg(test)]
    fn test_duration_once(input: &str) {
        use std::hint::black_box;

        let input = input.as_bytes();
        let len = input.len();

        let duration = {
            let start = std::time::Instant::now();
            let mut machine = Self::default();
            let mut cursor = cursor::Cursor::new(input);

            while cursor.pos < len {
                _ = black_box(machine.next(&mut cursor));

                cursor.advance();
            }

            start.elapsed()
        };
        eprintln!(
            "{}:   Duration: {:?}",
            std::any::type_name::<Self>(),
            duration
        );
    }

    #[cfg(test)]
    fn test_duration_n(n: usize, input: &str) {
        use std::hint::black_box;

        let input = input.as_bytes();
        let len = input.len();

        let duration = {
            let start = std::time::Instant::now();

            for _ in 0..n {

Frequently Asked Questions

What is the Machine class?
Machine is a class in the tailwindcss codebase, defined in crates/oxide/src/extractor/machine.rs.
Where is Machine defined?
Machine is defined in crates/oxide/src/extractor/machine.rs at line 33.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free