pub enum Resource {
Bundled {
bundled: String,
},
FileSystem {
file: PathBuf,
},
Raw {
raw: String,
},
}
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.
FileSystem
A resource that resides in the local file system.
Raw
A resource that init by user custom
Implementations§
Source§impl Resource
impl Resource
Sourcepub fn file_system(file: PathBuf) -> Resource
pub fn file_system(file: PathBuf) -> Resource
Creates a reference to the resource resident in the file system.
Sourcepub fn raw(raw: String) -> Resource
pub fn raw(raw: String) -> Resource
Creates a reference to the resource resident in the memory.
Sourcepub fn ckb_config<P: AsRef<Path>>(root_dir: P) -> Resource
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
.
Sourcepub fn miner_config<P: AsRef<Path>>(root_dir: P) -> Resource
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
.
Sourcepub fn db_options<P: AsRef<Path>>(root_dir: P) -> Resource
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
.
Sourcepub fn bundled_ckb_config() -> Resource
pub fn bundled_ckb_config() -> Resource
Creates the bundled CKB config file resource.
Sourcepub fn bundled_miner_config() -> Resource
pub fn bundled_miner_config() -> Resource
Creates the bundled CKB miner config file resource.
Sourcepub fn bundled_db_options() -> Resource
pub fn bundled_db_options() -> Resource
Creates the bundled RocksDB options file resource.
Sourcepub fn exported_in<P: AsRef<Path>>(root_dir: P) -> bool
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.
Sourcepub fn is_bundled(&self) -> bool
pub fn is_bundled(&self) -> bool
Returns true
if this is a bundled resource.
Sourcepub fn exists(&self) -> bool
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.
Sourcepub fn parent(&self) -> Option<&Path>
pub fn parent(&self) -> Option<&Path>
The parent directory of the resource.
It always returns None
on bundled resource.
Sourcepub fn absolutize<P: AsRef<Path>>(&mut self, base: P)
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
.
Sourcepub fn export<P: AsRef<Path>>(
&self,
context: &TemplateContext<'_>,
root_dir: P,
) -> Result<()>
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.