Struct ambient_std::asset_url::AbsAssetUrl
source · pub struct AbsAssetUrl(pub Url);
Expand description
This is a thin wrapper around Url, which is guaranteed to always be an absolute url (including when pointing to a local file).
It’s got a custom Debug implementation which just prints the url, which makes it useful in asset keys
Tuple Fields§
§0: Url
Implementations§
source§impl AbsAssetUrl
impl AbsAssetUrl
pub fn from_file_path(path: impl AsRef<Path>) -> Self
pub fn from_directory_path(path: impl AsRef<Path>) -> Self
pub fn from_asset_key(key: impl AsRef<str>) -> Result<Self, ParseError>
pub fn relative_cache_path(&self) -> String
pub fn absolute_cache_path(&self, assets: &AssetCache) -> PathBuf
sourcepub fn extension_is(&self, extension: impl AsRef<str>) -> bool
pub fn extension_is(&self, extension: impl AsRef<str>) -> bool
This is always lowercase
sourcepub fn add_extension(&self, extension: &str) -> Self
pub fn add_extension(&self, extension: &str) -> Self
Appends the extension: test.png -> test.png.hello
pub fn file_stem(&self) -> Option<&str>
pub fn to_file_path(&self) -> Result<Option<PathBuf>>
pub fn resolve( &self, url_or_relative_path: impl AsRef<str> ) -> Result<Self, ParseError>
sourcepub fn push(&self, path: impl AsRef<str>) -> Result<Self, ParseError>
pub fn push(&self, path: impl AsRef<str>) -> Result<Self, ParseError>
This appends [path] to the current path, with a /
joining them
sourcepub fn join(&self, path: impl AsRef<str>) -> Result<Self, ParseError>
pub fn join(&self, path: impl AsRef<str>) -> Result<Self, ParseError>
This joins the current url with a relative path. See https://docs.rs/url/latest/url/struct.Url.html#method.join for details how it works
sourcepub fn path(&self) -> RelativePathBuf
pub fn path(&self) -> RelativePathBuf
Returns the decoded path
pub fn set_path(&mut self, path: impl AsRef<str>)
pub fn relative_path(&self, path: impl AsRef<RelativePath>) -> RelativePathBuf
pub fn is_directory(&self) -> bool
sourcepub fn as_directory(&self) -> Self
pub fn as_directory(&self) -> Self
Ensures that this url ends with /
, which is interpreted as a “directory” by the Url package
sourcepub fn as_file(&self) -> Self
pub fn as_file(&self) -> Self
Ensures that this url doesn’t end with /
, which is interpreted as a “directory” by the Url package
sourcepub fn last_dir_name(&self) -> Option<&str>
pub fn last_dir_name(&self) -> Option<&str>
For a/b/c.png this returns b
pub fn to_download_url(&self, assets: &AssetCache) -> Result<Self, ParseError>
pub async fn download_bytes(&self, assets: &AssetCache) -> Result<Vec<u8>>
pub async fn download_string(&self, assets: &AssetCache) -> Result<String>
pub async fn download_json<T: 'static + Send + DeserializeOwned>( &self, assets: &AssetCache ) -> Result<T>
pub async fn download_toml<T: DeserializeOwned>( &self, assets: &AssetCache ) -> Result<T>
Trait Implementations§
source§impl Clone for AbsAssetUrl
impl Clone for AbsAssetUrl
source§fn clone(&self) -> AbsAssetUrl
fn clone(&self) -> AbsAssetUrl
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for AbsAssetUrl
impl Debug for AbsAssetUrl
source§impl<'de> Deserialize<'de> for AbsAssetUrl
impl<'de> Deserialize<'de> for AbsAssetUrl
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 AbsAssetUrl
impl Display for AbsAssetUrl
source§impl From<AbsAssetUrl> for AssetUrl
impl From<AbsAssetUrl> for AssetUrl
source§fn from(value: AbsAssetUrl) -> Self
fn from(value: AbsAssetUrl) -> Self
Converts to this type from the input type.
source§impl From<AbsAssetUrl> for String
impl From<AbsAssetUrl> for String
source§fn from(value: AbsAssetUrl) -> Self
fn from(value: AbsAssetUrl) -> Self
Converts to this type from the input type.
source§impl<T: GetAssetType> From<AbsAssetUrl> for TypedAssetUrl<T>
impl<T: GetAssetType> From<AbsAssetUrl> for TypedAssetUrl<T>
source§fn from(value: AbsAssetUrl) -> Self
fn from(value: AbsAssetUrl) -> Self
Converts to this type from the input type.
source§impl From<PathBuf> for AbsAssetUrl
impl From<PathBuf> for AbsAssetUrl
source§impl Hash for AbsAssetUrl
impl Hash for AbsAssetUrl
source§impl PartialEq<AbsAssetUrl> for AbsAssetUrl
impl PartialEq<AbsAssetUrl> for AbsAssetUrl
source§fn eq(&self, other: &AbsAssetUrl) -> bool
fn eq(&self, other: &AbsAssetUrl) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for AbsAssetUrl
impl Serialize for AbsAssetUrl
source§impl SyncAssetKey<AbsAssetUrl> for ContentBaseUrlKey
impl SyncAssetKey<AbsAssetUrl> for ContentBaseUrlKey
fn load(&self, assets: AssetCache) -> AbsAssetUrl
source§impl SyncAssetKey<AbsAssetUrl> for ServerBaseUrlKey
impl SyncAssetKey<AbsAssetUrl> for ServerBaseUrlKey
fn load(&self, _assets: AssetCache) -> AbsAssetUrl
impl Eq for AbsAssetUrl
impl StructuralEq for AbsAssetUrl
impl StructuralPartialEq for AbsAssetUrl
Auto Trait Implementations§
impl RefUnwindSafe for AbsAssetUrl
impl Send for AbsAssetUrl
impl Sync for AbsAssetUrl
impl Unpin for AbsAssetUrl
impl UnwindSafe for AbsAssetUrl
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
Mutably borrows from an owned value. Read more
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.