pub struct DataContent {
pub uri: String,
pub media_type: Option<String>,
}Expand description
Inline binary data encoded as a data: URI.
Fields§
§uri: String§media_type: Option<String>Implementations§
Source§impl DataContent
impl DataContent
Sourcepub fn from_bytes(data: &[u8], media_type: impl Into<String>) -> DataContent
pub fn from_bytes(data: &[u8], media_type: impl Into<String>) -> DataContent
Build a data URI from raw bytes and a media type.
Sourcepub fn from_uri(uri: impl Into<String>) -> Result<DataContent, Error>
pub fn from_uri(uri: impl Into<String>) -> Result<DataContent, Error>
Build from an existing data: URI, validating its shape and inferring
the media type from it.
Mirrors upstream’s detect_media_type_from_base64 (_types.py:124),
which rejects a malformed data URI instead of silently mis-slicing it.
The prior lenient split(";base64,")[1] would panic or yield garbage on
input that merely looked close enough.
§Errors
Returns Error::Content when uri does not start with data:, has
no , separating the header from the payload, or is not declared
;base64.
Sourcepub fn media_type_from_uri(uri: &str) -> Result<String, Error>
pub fn media_type_from_uri(uri: &str) -> Result<String, Error>
Validate a data: URI and return the media type it declares.
An empty media type (data:;base64,...) is permitted — the URI is
well-formed and the type is simply unstated — and yields an empty
string, matching upstream, which only rejects structural problems.
Trait Implementations§
Source§impl Clone for DataContent
impl Clone for DataContent
Source§fn clone(&self) -> DataContent
fn clone(&self) -> DataContent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more