pub enum ResourceKey<'a> {
Value(Cow<'a, str>),
Position(usize),
}Expand description
A key identifying where the content is held for a Resource, either by
string or numeric position.
§Examples
let position_key = ResourceKey::from(5);
let str_key = ResourceKey::from("OEBPS/nav/toc.xhtml");
// A path may be passed as well, although it must contain valid UTF-8.
// Otherwise, the requested file won't be found and an error will
// be propagated from methods that process a `ResourceKey`:
let str_key2 = ResourceKey::from(Path::new("EPUB/toc.ncx"));
assert!(matches!(position_key, ResourceKey::Position(5)));
assert!(matches!(str_key, ResourceKey::Value(Cow::Borrowed("OEBPS/nav/toc.xhtml"))));
assert!(matches!(str_key2, ResourceKey::Value(Cow::Borrowed("EPUB/toc.ncx"))));Variants§
Value(Cow<'a, str>)
A string-based key (e.g., file path, URI)
that references where a resource is stored.
When using the From<&Path> impl, the input must be
valid UTF-8; any non-UTF-8 sequences will be replaced with �.
Position(usize)
Implementations§
Source§impl ResourceKey<'_>
impl ResourceKey<'_>
Trait Implementations§
Source§impl<'a> Clone for ResourceKey<'a>
impl<'a> Clone for ResourceKey<'a>
Source§fn clone(&self) -> ResourceKey<'a>
fn clone(&self) -> ResourceKey<'a>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Debug for ResourceKey<'a>
impl<'a> Debug for ResourceKey<'a>
impl<'a> Eq for ResourceKey<'a>
Source§impl<'a> From<&'a Path> for ResourceKey<'a>
It is expected that the given path is UTF-8 compliant.
Otherwise, the associated resource will never be found within an ebook.
impl<'a> From<&'a Path> for ResourceKey<'a>
It is expected that the given path is UTF-8 compliant.
Otherwise, the associated resource will never be found within an ebook.
For fallible operations, prefer Path::to_str,
which ensures the given string is UTF-8 compliant:
let epub = Epub::open("tests/ebooks/example_epub")?;
let mut path = PathBuf::from("/EPUB");
path.push("c1.xhtml");
// `path` is implicitly turned into a `Resource`
let bytes_a = epub.read_resource_bytes(&*path)?;
if let Some(utf8_value) = path.to_str() {
// Explicitly providing a `Resource`
let resource = Resource::from(utf8_value);
let bytes_b = epub.read_resource_bytes(resource)?;
assert_eq!(bytes_a, bytes_b);
}§Windows
This conversion allocates on Windows operating systems to convert path separators, if needed.
Specifically, replacing back-slashes (\) with forward-slashes (/).
For example: path\to\content.xhtml → path/to/content.xhtml
Source§impl<'a> From<&'a ResourceKey<'a>> for ResourceKey<'a>
impl<'a> From<&'a ResourceKey<'a>> for ResourceKey<'a>
Source§impl<'a> From<&'a String> for ResourceKey<'a>
impl<'a> From<&'a String> for ResourceKey<'a>
Source§impl<'a> From<&'a str> for ResourceKey<'a>
impl<'a> From<&'a str> for ResourceKey<'a>
Source§impl<'a> From<Href<'a>> for ResourceKey<'a>
impl<'a> From<Href<'a>> for ResourceKey<'a>
Source§impl From<String> for ResourceKey<'_>
impl From<String> for ResourceKey<'_>
Source§impl From<usize> for ResourceKey<'_>
impl From<usize> for ResourceKey<'_>
Source§impl<'a> Hash for ResourceKey<'a>
impl<'a> Hash for ResourceKey<'a>
Source§impl<'a> PartialEq for ResourceKey<'a>
impl<'a> PartialEq for ResourceKey<'a>
impl<'a> StructuralPartialEq for ResourceKey<'a>
Auto Trait Implementations§
impl<'a> Freeze for ResourceKey<'a>
impl<'a> RefUnwindSafe for ResourceKey<'a>
impl<'a> Send for ResourceKey<'a>
impl<'a> Sync for ResourceKey<'a>
impl<'a> Unpin for ResourceKey<'a>
impl<'a> UnsafeUnpin for ResourceKey<'a>
impl<'a> UnwindSafe for ResourceKey<'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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.