Struct Resource

Source
pub struct Resource<'a, X: 'a>
where [X]: ToOwned<Owned = Vec<X>>,
{
Show 28 fields pub name: Cow<'a, str>, pub is_python_module: bool, pub is_python_builtin_extension_module: bool, pub is_python_frozen_module: bool, pub is_python_extension_module: bool, pub is_shared_library: bool, pub is_utf8_filename_data: bool, pub is_python_package: bool, pub is_python_namespace_package: bool, pub in_memory_source: Option<Cow<'a, [X]>>, pub in_memory_bytecode: Option<Cow<'a, [X]>>, pub in_memory_bytecode_opt1: Option<Cow<'a, [X]>>, pub in_memory_bytecode_opt2: Option<Cow<'a, [X]>>, pub in_memory_extension_module_shared_library: Option<Cow<'a, [X]>>, pub in_memory_package_resources: Option<HashMap<Cow<'a, str>, Cow<'a, [X]>>>, pub in_memory_distribution_resources: Option<HashMap<Cow<'a, str>, Cow<'a, [X]>>>, pub in_memory_shared_library: Option<Cow<'a, [X]>>, pub shared_library_dependency_names: Option<Vec<Cow<'a, str>>>, pub relative_path_module_source: Option<Cow<'a, Path>>, pub relative_path_module_bytecode: Option<Cow<'a, Path>>, pub relative_path_module_bytecode_opt1: Option<Cow<'a, Path>>, pub relative_path_module_bytecode_opt2: Option<Cow<'a, Path>>, pub relative_path_extension_module_shared_library: Option<Cow<'a, Path>>, pub relative_path_package_resources: Option<HashMap<Cow<'a, str>, Cow<'a, Path>>>, pub relative_path_distribution_resources: Option<HashMap<Cow<'a, str>, Cow<'a, Path>>>, pub file_executable: bool, pub file_data_embedded: Option<Cow<'a, [X]>>, pub file_data_utf8_relative_path: Option<Cow<'a, str>>,
}
Expand description

Represents an indexed resource.

The resource has a name and type affinity via various is_* fields.

The data for the resource may be present in the instance or referenced via an external filesystem path.

Data fields are Cow<T> and can either hold a borrowed reference or owned data. This allows the use of a single type to both hold data or reference it from some other location.

Fields§

§name: Cow<'a, str>

The resource name.

§is_python_module: bool

Whether this resource defines a Python module/package.

§is_python_builtin_extension_module: bool

Whether this resource defines a builtin extension module.

§is_python_frozen_module: bool

Whether this resource defines a frozen Python module.

§is_python_extension_module: bool

Whether this resource defines a Python extension module.

§is_shared_library: bool

Whether this resource defines a shared library.

§is_utf8_filename_data: bool

Whether this resource defines data for an arbitrary file.

If set, name is the UTF-8 encoded filename being represented.

The file data should exist in one of the file_data_* fields.

§is_python_package: bool

Whether the Python module is a package.

§is_python_namespace_package: bool

Whether the Python module is a namespace package.

§in_memory_source: Option<Cow<'a, [X]>>

Python module source code to use to import module from memory.

§in_memory_bytecode: Option<Cow<'a, [X]>>

Python module bytecode to use to import module from memory.

§in_memory_bytecode_opt1: Option<Cow<'a, [X]>>

Python module bytecode at optimized level 1 to use to import from memory.

§in_memory_bytecode_opt2: Option<Cow<'a, [X]>>

Python module bytecode at optimized level 2 to use to import from memory.

§in_memory_extension_module_shared_library: Option<Cow<'a, [X]>>

Native machine code constituting a shared library for an extension module which can be imported from memory. (Not supported on all platforms.)

§in_memory_package_resources: Option<HashMap<Cow<'a, str>, Cow<'a, [X]>>>

Mapping of virtual filename to data for resources to expose to Python’s importlib.resources API via in-memory data access.

§in_memory_distribution_resources: Option<HashMap<Cow<'a, str>, Cow<'a, [X]>>>

Mapping of virtual filename to data for package distribution metadata to expose to Python’s importlib.metadata API via in-memory data access.

§in_memory_shared_library: Option<Cow<'a, [X]>>

Native machine code constituting a shared library which can be imported from memory.

In-memory loading of shared libraries is not supported on all platforms.

§shared_library_dependency_names: Option<Vec<Cow<'a, str>>>

Sequence of names of shared libraries this resource depends on.

§relative_path_module_source: Option<Cow<'a, Path>>

Relative path to file containing Python module source code.

§relative_path_module_bytecode: Option<Cow<'a, Path>>

Relative path to file containing Python module bytecode.

§relative_path_module_bytecode_opt1: Option<Cow<'a, Path>>

Relative path to file containing Python module bytecode at optimization level 1.

§relative_path_module_bytecode_opt2: Option<Cow<'a, Path>>

Relative path to file containing Python module bytecode at optimization level 2.

§relative_path_extension_module_shared_library: Option<Cow<'a, Path>>

Relative path to file containing Python extension module loadable as a shared library.

§relative_path_package_resources: Option<HashMap<Cow<'a, str>, Cow<'a, Path>>>

Mapping of Python package resource names to relative filesystem paths for those resources.

§relative_path_distribution_resources: Option<HashMap<Cow<'a, str>, Cow<'a, Path>>>

Mapping of Python package distribution files to relative filesystem paths for those resources.

§file_executable: bool

Whether this resource’s file data should be executable.

§file_data_embedded: Option<Cow<'a, [X]>>

Holds arbitrary file data in memory.

§file_data_utf8_relative_path: Option<Cow<'a, str>>

Holds arbitrary file data in a relative path encoded in UTF-8.

Implementations§

Source§

impl<'a, X> Resource<'a, X>
where [X]: ToOwned<Owned = Vec<X>>,

Source

pub fn merge_from(&mut self, other: Resource<'a, X>) -> Result<(), &'static str>

Merge another resource into this one.

Fields from other will overwrite fields from self.

Source

pub fn to_owned(&self) -> Resource<'static, X>

Source§

impl<'a, X: Clone + 'a> Resource<'a, X>
where [X]: ToOwned<Owned = Vec<X>>,

Source

pub fn is_meaningful(&self) -> bool

Whether the resource is meaningful.

The resource is meaningful if it has data attached or is a package.

Source

pub fn index_v1_length(&self) -> usize

Compute length of index entry for version 1 payload format.

Source

pub fn field_blob_length(&self, field: ResourceField) -> usize

Compute the length of a field.

Interior padding is not part of the returned length.

Source

pub fn field_blob_interior_padding_length( &self, field: ResourceField, padding: BlobInteriorPadding, ) -> usize

Compute the size of interior padding for a specific field.

Source

pub fn write_index_v1<W: Write>(&self, dest: &mut W) -> Result<()>

Write the version 1 index entry for a resource instance.

Trait Implementations§

Source§

impl<'a, X> AsRef<Resource<'a, X>> for Resource<'a, X>
where [X]: ToOwned<Owned = Vec<X>>,

Source§

fn as_ref(&self) -> &Resource<'a, X>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a, X: Clone + 'a> Clone for Resource<'a, X>
where [X]: ToOwned<Owned = Vec<X>>,

Source§

fn clone(&self) -> Resource<'a, X>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, X: Debug + 'a> Debug for Resource<'a, X>
where [X]: ToOwned<Owned = Vec<X>>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, X> Default for Resource<'a, X>
where [X]: ToOwned<Owned = Vec<X>>,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, X: PartialEq + 'a> PartialEq for Resource<'a, X>
where [X]: ToOwned<Owned = Vec<X>>,

Source§

fn eq(&self, other: &Resource<'a, X>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, X: Eq + 'a> Eq for Resource<'a, X>
where [X]: ToOwned<Owned = Vec<X>>,

Source§

impl<'a, X: 'a> StructuralPartialEq for Resource<'a, X>
where [X]: ToOwned<Owned = Vec<X>>,

Auto Trait Implementations§

§

impl<'a, X> Freeze for Resource<'a, X>

§

impl<'a, X> RefUnwindSafe for Resource<'a, X>
where X: RefUnwindSafe,

§

impl<'a, X> Send for Resource<'a, X>
where X: Sync + Send,

§

impl<'a, X> Sync for Resource<'a, X>
where X: Sync,

§

impl<'a, X> Unpin for Resource<'a, X>
where X: Unpin,

§

impl<'a, X> UnwindSafe for Resource<'a, X>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.