pub struct Css<'a> { /* private fields */ }Expand description
§CSS Stylesheet.
This struct is used to parse and validate CSS/SCSS content, and optionally minify it for production use.
Note: CSS modules are not supported, however SCSS imports are.
§Use
If you already have the CSS gathered into a string, you can instantiate
this object using From<&str> or From<String>.
More often, you’ll want to load the contents directly from a file, which
can be done using TryFrom<&Path>. If the file extension is .sass or
.scss, the contents will be run through the SCSS interpreter to generate
the CSS, otherwise if the file extension is .css, the file contents will
be used directly.
Note: SCSS is only supported when read from a file.
Once initialized, you can convert your Css object into an owned string
(i.e. browser-ready CSS) using the Css::take or Css::minified
methods.
§Examples
use guff_css::Css;
use std::path::Path;
// Load, validate, and return CSS from a file.
let css = Css::try_from(Path::new("../skel/style.css"))
.unwrap()
.take()
.unwrap();
// The same thing, but starting from SCSS, and minifying!
let css = Css::try_from(Path::new("../skel/style.scss"))
.unwrap()
.minified(None)
.unwrap();Implementations§
Source§impl Css<'_>
impl Css<'_>
Sourcepub fn minified(self, browsers: Option<Browsers>) -> Result<String, GuffError>
pub fn minified(self, browsers: Option<Browsers>) -> Result<String, GuffError>
§Minify.
This works just like Css::take, except the CSS is aggressively
minified before being returned.
Speaking of aggression, the latest and greatest CSS features are
sometimes leveraged for additional space savings. The browsers
argument can be used to override this behavior, maintaining backward
compatibility with the browsers specified.
§Errors
If the CSS cannot be parsed or errors occur during minification, an error will be returned.
Trait Implementations§
Source§impl<'a> TryFrom<&'a Path> for Css<'a>
impl<'a> TryFrom<&'a Path> for Css<'a>
Source§fn try_from(src: &'a Path) -> Result<Self, Self::Error>
fn try_from(src: &'a Path) -> Result<Self, Self::Error>
§From File.
This will attempt to load the contents of the given file, using its extension as a filetype hint.
If the file ends with .sass or .scss, it is assumed to be SCSS, and
will be run through the SCSS compiler to produce valid CSS.
If the file ends with .css, the contents are presumed to already be
valid CSS.
§Errors
If the file is missing, unreadable, or does not end with a CSS or SCSS extension, an error will be returned. For SCSS, processing errors will be bubbled up if encountered.
Auto Trait Implementations§
impl<'a> Freeze for Css<'a>
impl<'a> RefUnwindSafe for Css<'a>
impl<'a> Send for Css<'a>
impl<'a> Sync for Css<'a>
impl<'a> Unpin for Css<'a>
impl<'a> UnwindSafe for Css<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more