pub struct ReceivedMime(/* private fields */);Expand description
A mime type as some other application spelled it.
§Why this is a second type
MimeType is Copy, which means its escape hatch is
Other(&'static str) — fine for something this engine
names in its own source, and structurally unable to hold a string that
arrived at runtime from another process. Every incoming mime is exactly
that: an X11 TARGETS reply, a Wayland data_offer.offer, or a browser
DataTransfer.types entry, all of them arbitrary and none of them
'static.
So the outgoing side stays Copy and the incoming side owns its string. The
asymmetry is the point: a clipboard write names a format the engine chose,
and a clipboard read reports a format someone else chose.
§Fidelity
The literal spelling is preserved rather than canonicalized.
recognized maps it onto a MimeType where one fits,
but ReceivedMime::new("text/plain") keeps "text/plain" — because a
backend answering an X11 SelectionRequest has to echo back the target
atom that was asked for, and rewriting it to
text/plain;charset=utf-8 would produce a reply the peer does not
recognize.
Implementations§
Source§impl ReceivedMime
impl ReceivedMime
Sourcepub fn new(mime: &str) -> Self
pub fn new(mime: &str) -> Self
Wraps a mime string that arrived from another application.
Borrows rather than allocating when the string is byte-identical to one of the engine’s own — which covers the overwhelmingly common case of a crcbl-to-crcbl copy — and allocates otherwise.
Sourcepub fn recognized(&self) -> Option<MimeType>
pub fn recognized(&self) -> Option<MimeType>
The MimeType this corresponds to, if the engine knows the format.
None means “some other application’s format” — loggable, forwardable,
and not something the engine can interpret.
Sourcepub fn matches(&self, mime: MimeType) -> bool
pub fn matches(&self, mime: MimeType) -> bool
Whether this is the format mime names, allowing for the alternative
spellings MimeType::recognize accepts.
This is the comparison a paste handler wants: asking for
MimeType::TextUtf8 and receiving "text/plain" is a match, and
comparing the strings directly would say it is not.