Home / File/ machine.rs — tailwindcss Source File

machine.rs — tailwindcss Source File

Architecture documentation for machine.rs, a rust file in the tailwindcss codebase. 3 imports, 0 dependents.

File rust Oxide Extractor 3 imports 2 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  994f1fdb_7990_63cc_647a_57f7c007871a["machine.rs"]
  96a36755_a007_15e1_ec6c_526c02d24b9b["crate::cursor"]
  994f1fdb_7990_63cc_647a_57f7c007871a --> 96a36755_a007_15e1_ec6c_526c02d24b9b
  6e8d9081_ad2a_8ce1_a339_9afeac221d22["crate::throughput::Throughput"]
  994f1fdb_7990_63cc_647a_57f7c007871a --> 6e8d9081_ad2a_8ce1_a339_9afeac221d22
  a89aa61c_e4aa_9168_687e_995e52c4d4ba["std::hint::black_box"]
  994f1fdb_7990_63cc_647a_57f7c007871a --> a89aa61c_e4aa_9168_687e_995e52c4d4ba
  style 994f1fdb_7990_63cc_647a_57f7c007871a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

use crate::cursor;

#[derive(Debug, Clone, Copy)]
pub struct Span {
    /// Inclusive start position of the span
    pub start: usize,

    /// Inclusive end position of the span
    pub end: usize,
}

impl Span {
    pub fn new(start: usize, end: usize) -> Self {
        Self { start, end }
    }

    #[inline(always)]
    pub fn slice<'a>(&self, input: &'a [u8]) -> &'a [u8] {
        &input[self.start..=self.end]
    }
}

#[derive(Debug, Default)]
pub enum MachineState {
    /// Machine is not doing anything at the moment
    #[default]
    Idle,

    /// Machine is done parsing and has extracted a span
    Done(Span),
}

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();
// ... (102 more lines)

Domain

Subdomains

Functions

Classes

Dependencies

  • crate::cursor
  • crate::throughput::Throughput
  • std::hint::black_box

Frequently Asked Questions

What does machine.rs do?
machine.rs is a source file in the tailwindcss codebase, written in rust. It belongs to the Oxide domain, Extractor subdomain.
What functions are defined in machine.rs?
machine.rs defines 2 function(s): new, slice.
What does machine.rs depend on?
machine.rs imports 3 module(s): crate::cursor, crate::throughput::Throughput, std::hint::black_box.
Where is machine.rs in the architecture?
machine.rs is located at crates/oxide/src/extractor/machine.rs (domain: Oxide, subdomain: Extractor, directory: crates/oxide/src/extractor).

Analyze Your Own Codebase

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

Try Supermodel Free