pub struct ModulePath {
pub origin: PathOrigin,
pub components: Vec<String>,
}Fields§
§origin: PathOrigin§components: Vec<String>Implementations§
Source§impl ModulePath
impl ModulePath
Sourcepub fn new(origin: PathOrigin, components: Vec<String>) -> ModulePath
Available on crate feature imports only.
pub fn new(origin: PathOrigin, components: Vec<String>) -> ModulePath
imports only.Create a new module path from components.
Precondition: the path components must be valid WGSL identifiers.
Sourcepub fn new_root() -> ModulePath
Available on crate feature imports only.
pub fn new_root() -> ModulePath
imports only.Create a module path that refers to the root module, i.e. package.
Technically import package; is not a valid import statement in WESL code.
However adding an item to the path, such as import package::foo; points at
declaration foo in the root module.
Sourcepub fn from_path(path: impl AsRef<Path>) -> ModulePath
Available on crate feature imports only.
pub fn from_path(path: impl AsRef<Path>) -> ModulePath
imports only.Create a new module path from a filesystem path.
- Paths with a root (leading
/on Unix) producepackage::paths. - Relative paths (starting with
.or..) produceself::orsuper::paths. - The file extension is ignored.
- The path is canonicalized and to do so it does NOT follow symlinks.
Preconditions:
- The path must not start with a prefix, like C:\ on windows.
- The path must contain at least one named component.
- Named components must be valid module names. (Module names are WGSL identifiers + certain reserved names, see wesl-spec#127)
Sourcepub fn to_path_buf(&self) -> PathBuf
Available on crate feature imports only.
pub fn to_path_buf(&self) -> PathBuf
imports only.Create a PathBuf from a ModulePath.
package::paths are rooted (start with/).- self::
orsuper::are relative (starting with.or..). - There is no file extension.
Sourcepub fn push(&mut self, item: &str)
Available on crate feature imports only.
pub fn push(&mut self, item: &str)
imports only.Append a component to the path.
Precondition: the item must be a valid WGSL identifier.
Sourcepub fn first(&self) -> Option<&str>
Available on crate feature imports only.
pub fn first(&self) -> Option<&str>
imports only.Get the first component of the module path.
Sourcepub fn last(&self) -> Option<&str>
Available on crate feature imports only.
pub fn last(&self) -> Option<&str>
imports only.Get the last component of the module path.
Sourcepub fn join(self, suffix: impl IntoIterator<Item = String>) -> ModulePath
Available on crate feature imports only.
pub fn join(self, suffix: impl IntoIterator<Item = String>) -> ModulePath
imports only.Append suffix to the module path.
Sourcepub fn join_path(&self, suffix: &ModulePath) -> ModulePath
Available on crate feature imports only.
pub fn join_path(&self, suffix: &ModulePath) -> ModulePath
imports only.Append suffix to the module path.
This function produces a ModulePath relative to self, as if suffix was
imported from module self.
- If
suffixis relative, it appends its components toself. - If
suffixif absolute or package, it ignoresselfcomponents. - If both
selfandsuffixare package paths, thensuffiximports from a sub-package. The package is renamed with a slash separating package names. (TODO: this is a hack)
Sourcepub fn starts_with(&self, prefix: &ModulePath) -> bool
Available on crate feature imports only.
pub fn starts_with(&self, prefix: &ModulePath) -> bool
imports only.Whether the module path starts with a prefix.
Sourcepub fn is_root(&self) -> bool
Available on crate feature imports only.
pub fn is_root(&self) -> bool
imports only.Whether the module path points at the route module.
See Self::new_root.
Trait Implementations§
Source§impl Clone for ModulePath
impl Clone for ModulePath
Source§fn clone(&self) -> ModulePath
fn clone(&self) -> ModulePath
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ModulePath
impl Debug for ModulePath
Source§impl<'de> Deserialize<'de> for ModulePath
impl<'de> Deserialize<'de> for ModulePath
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ModulePath, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ModulePath, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for ModulePath
Available on crate feature imports only.
impl Display for ModulePath
imports only.Source§impl FromStr for ModulePath
Available on crate feature imports only.
impl FromStr for ModulePath
imports only.Source§impl Hash for ModulePath
impl Hash for ModulePath
Source§impl PartialEq for ModulePath
impl PartialEq for ModulePath
Source§impl Serialize for ModulePath
impl Serialize for ModulePath
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for ModulePath
impl StructuralPartialEq for ModulePath
Auto Trait Implementations§
impl Freeze for ModulePath
impl RefUnwindSafe for ModulePath
impl Send for ModulePath
impl Sync for ModulePath
impl Unpin for ModulePath
impl UnwindSafe for ModulePath
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more