Struct Stylesheet

Source
pub struct Stylesheet {
    pub rules: CssRules,
    pub source_map_url: Option<String>,
    pub source_url: Option<String>,
}
Expand description

Represents an entire CSS stylesheet. The values of property declarations are currently stored as a string. Parsing property declarations is a monster job. If you feel like helping…

Fields§

§rules: CssRules

The stylesheet’s rules.

§source_map_url: Option<String>

An optional source map for this stylesheet.

§source_url: Option<String>

An optional source URL for this stylesheet.

Implementations§

Source§

impl Stylesheet

Source

pub fn to_file_path<P: AsRef<Path>>( &self, stylesheet_file_path: P, include_source_urls: bool, ) -> Result<(), StylesheetError>

Serializes a Stylesheet to a file path, optionally including source-map and source-url comments. Will create or truncate stylesheet_file_path as required. Convenience method wrapped to_css().

Source

pub fn to_css_string(&self, include_source_urls: bool) -> String

Serializes a Stylesheet as a string, optionally including source-map and source-url comments. Convenience method wrapped to_css().

Source

pub fn to_bytes(&self, include_source_urls: bool) -> Vec<u8>

Serializes a Stylesheet to a vector of UTF-8 encoded bytes. Convenience method wrapped to_css_string().

Source

pub fn to_css<W: Write>( &self, destination: &mut W, include_source_urls: bool, ) -> Result

Serializes a Stylesheet, optionally including source-map and source-url comments.

Source

pub fn from_file_path<P: AsRef<Path>>( html_document_file_path: P, ) -> Result<Self, StylesheetError>

Loads and parses a Stylesheet.

Source

pub fn parse(css: &str) -> Result<Self, ParseError<'_, CustomParseError<'_>>>

Parses a string of CSS to produce a stylesheet. Can be used with the contents of a CSS file. Assumes the string is UTF-8 encoded. Does not use a stream of bytes as parsing CSS involves going backwards and forwards a lot… CSS parsing is somewhat evil and is not particularly efficient. The parser does apply a few small modifications to the incoming CSS, normalizing some pseudo-class, psuedo-element and media query names. The parser does not parse properties as such, simply keeping them as a CSS string. Hopefully it will one day - there are only 200 odd specialist rules to implement.

Trait Implementations§

Source§

impl Clone for Stylesheet

Source§

fn clone(&self) -> Stylesheet

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Stylesheet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl HasCssRules for Stylesheet

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.