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
pub fn new(origin: PathOrigin, components: Vec<String>) -> ModulePath
Create a new module path from components.
Precondition: the path components must be valid WGSL identifiers.
Sourcepub fn new_root() -> ModulePath
pub fn new_root() -> ModulePath
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
pub fn from_path(path: impl AsRef<Path>) -> ModulePath
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
pub fn to_path_buf(&self) -> PathBuf
Create a PathBuf
from a ModulePath
.
package::
paths are rooted (start with/
).- self::
or
super::are relative (starting with
.or
..)
. - There is no file extension.
Sourcepub fn push(&mut self, item: &str)
pub fn push(&mut self, item: &str)
Append a component to the path.
Precondition: the item
must be a valid WGSL identifier.
Sourcepub fn join(self, suffix: impl IntoIterator<Item = String>) -> ModulePath
pub fn join(self, suffix: impl IntoIterator<Item = String>) -> ModulePath
Append suffix
to the module path.
Sourcepub fn join_path(&self, suffix: &ModulePath) -> ModulePath
pub fn join_path(&self, suffix: &ModulePath) -> ModulePath
Append suffix
to the module path.
This function produces a ModulePath
relative to self
, as if suffix
was
imported from module self
.
- If
suffix
is relative, it appends its components toself
. - If
suffix
if absolute or package, it ignoresself
components. - If both
self
andsuffix
are package paths, thensuffix
imports 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
pub fn starts_with(&self, prefix: &ModulePath) -> bool
Whether the module path starts with a prefix
.
Sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
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
impl Display for ModulePath
Source§impl FromStr for ModulePath
impl FromStr for ModulePath
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