Skip to main content

rust_css_parser/printer/
result.rs

1//! Port of `src/printer/result.ts` (rendering part, see the host api for the javascript classes).
2
3use crate::printer::sourcemap::SourceMap;
4use crate::types::ErrorDescription;
5
6/// `RenderResult`: the rendered css (utf-8 bytes, decoded lazily by the bindings)
7#[derive(Clone, Debug)]
8pub struct RenderResult {
9    pub bytes: Vec<u8>,
10    pub errors: Vec<ErrorDescription>,
11    pub total: String,
12    pub map: Option<SourceMap>,
13    /// length of the css in utf-16 code units (`code.length`)
14    pub code_length: usize,
15}
16
17impl RenderResult {
18    /// the rendered css
19    pub fn code(&self) -> &str {
20        std::str::from_utf8(&self.bytes).unwrap_or_default()
21    }
22
23    /// `RenderResult.codeLength()`
24    pub fn code_length(&self) -> usize {
25        self.code_length
26    }
27}