Struct FilesystemSource

Source
pub struct FilesystemSource { /* private fields */ }
Expand description

A Source that loads packages from the filesystem. This is a good source to use for development, or if you don’t care about packaging your data files into an archive.

Implementations§

Source§

impl FilesystemSource

Source

pub fn new(directory: &str, trust: TrustLevel) -> FilesystemSource

Creates a new FilesystemSource using the given directory to look for packages in

Examples found in repository?
examples/basic.rs (line 44)
40fn main()
41{
42    println!("Listing items in mypackage/text:");
43    
44    let mut source = FilesystemSource::new("examples", TrustLevel::TrustedSource);
45    let iter = source.iter_entries("mypackage", "text");
46    
47    for entry in iter
48    {
49        match entry
50        {
51            Ok(pathname) => println!("{}", pathname),
52            Err(error) => println!("Error: {}", error)
53        }
54    }
55    
56    println!("Loading files from mypackage/text...");
57    
58    let source_manager = Rc::new(RefCell::new(SourceManager::new()));
59    source_manager.borrow_mut().add_source(Box::new(source));
60    
61    let mut store = DataStore::<TextData>::new(source_manager);
62    
63    store.load_package("mypackage").expect("Failed to load package.");
64    
65    for name in &["emoji.txt", "missingfile.txt", "loremipsum.txt"]
66    {
67        match store.get_id("mypackage", name)
68        {
69            Ok(id) =>
70            {
71                println!("Contents of {}:", name);
72                match store.get(id)
73                {
74                    Some(data) => println!("{}", data.text),
75                    None => println!("(not found)"),
76                }
77            }
78            Err(error) =>
79            {
80                println!("Error for {}:\n{}", name, error);
81            }
82        }
83        
84        println!("");
85    }
86}

Trait Implementations§

Source§

impl Source for FilesystemSource

Source§

fn get_uri(&self) -> &str

The path that this Source originates from. Only used for debug purposes.
Source§

fn has_package(&self, package_name: &str) -> bool

Returns true if the Source has a package of the given name, otherwise returns false
Source§

fn list_packages(&mut self) -> Vec<String>

Returns a list of all packages available in this Source. Do not call this repeatedly!
Source§

fn read_file<'a>( &'a mut self, package_name: &str, pathname: &str, ) -> Result<Box<dyn ReadSeek + 'a>, PackageError>

Returns a Read + Seek for the file at the given pathname, if one exists.
Source§

fn write_file<'a>( &'a mut self, package_name: &str, pathname: &str, ) -> Result<Box<dyn Write + 'a>, PackageError>

Returns a Write for the file at the given pathname.
Source§

fn iter_entries<'a>( &'a mut self, package_name: &str, type_folder: &str, ) -> Box<dyn Iterator<Item = Result<String, PackageError>> + 'a>

Returns an iterator through the items in a given package, if the Source has said package
Source§

fn trust_level(&self, _package_name: &str) -> TrustLevel

Returns the source’s trust level for the given package. Trusted sources are able to load resource types marked as requiring trust.

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> Same for T

Source§

type Output = T

Should always be Self
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.