Enum ckb_resource::Resource

source ·
pub enum Resource {
    Bundled {
        bundled: String,
    },
    FileSystem {
        file: PathBuf,
    },
}
Expand description

Represents a resource, which is either bundled in the CKB binary or resident in the local file system.

Variants§

§

Bundled

A resource that bundled in the CKB binary.

Fields

§bundled: String

The identifier of the bundled resource.

§

FileSystem

A resource that resides in the local file system.

Fields

§file: PathBuf

The file path to the resource.

Implementations§

source§

impl Resource

source

pub fn bundled(bundled: String) -> Resource

Creates a reference to the bundled resource.

source

pub fn file_system(file: PathBuf) -> Resource

Creates a reference to the resource recident in the file system.

source

pub fn ckb_config<P: AsRef<Path>>(root_dir: P) -> Resource

Creates the CKB config file resource from the file system.

It searches the file name CKB_CONFIG_FILE_NAME in the directory root_dir.

source

pub fn miner_config<P: AsRef<Path>>(root_dir: P) -> Resource

Creates the CKB miner config file resource from the file system.

It searches the file name MINER_CONFIG_FILE_NAME in the directory root_dir.

source

pub fn db_options<P: AsRef<Path>>(root_dir: P) -> Resource

Creates the RocksDB options file resource from the file system.

It searches the file name DB_OPTIONS_FILE_NAME in the directory root_dir.

source

pub fn bundled_ckb_config() -> Resource

Creates the bundled CKB config file resource.

source

pub fn bundled_miner_config() -> Resource

Creates the bundled CKB miner config file resource.

source

pub fn bundled_db_options() -> Resource

Creates the bundled RocksDB options file resource.

source

pub fn exported_in<P: AsRef<Path>>(root_dir: P) -> bool

Checks whether any of the bundled resource has been exported in the specified directory.

This can be used to avoid overwriting to export all the bundled resources to the specified directory.

source

pub fn is_bundled(&self) -> bool

Returns true if this is a bundled resource.

source

pub fn exists(&self) -> bool

Returns true if the resource exists.

The bundled resource exists only when the identifier is included in the bundle.

The file system resource exists only when the file exists.

source

pub fn parent(&self) -> Option<&Path>

The parent directory of the resource.

It always returns None on bundled resource.

source

pub fn absolutize<P: AsRef<Path>>(&mut self, base: P)

Modifies the file system resource to ensure the path is absolute.

If the path is relative, expand the path relative to the directory base.

source

pub fn get(&self) -> Result<Cow<'static, [u8]>>

Gets resource content.

source

pub fn read(&self) -> Result<Box<dyn Read>>

Gets resource content via an input stream.

source

pub fn export<P: AsRef<Path>>( &self, context: &TemplateContext<'_>, root_dir: P ) -> Result<()>

Exports a bundled resource.

This function returns Ok immediately when invoked on a file system resource.

The file is exported to the path by combining root_dir and the resource identifier.

These bundled files can be customized for different chains using spec branches. See Template.

Trait Implementations§

source§

impl Clone for Resource

source§

fn clone(&self) -> Resource

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Resource

source§

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

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

impl<'de> Deserialize<'de> for Resource

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Resource

source§

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

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

impl PartialEq for Resource

source§

fn eq(&self, other: &Resource) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Resource

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Resource

source§

impl StructuralPartialEq for Resource

Auto Trait Implementations§

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> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

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,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,