ckb_resource

Enum 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 resident 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

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

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

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

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