pub struct PluginAssets { /* private fields */ }Expand description
A set of files compiled into a crate and served with content-hashed URLs.
Build one with plugin_assets! (a directory; embed-assets feature) or
PluginAssets::from_files (an explicit list), store it in a static,
and install it with
AppBuilder::plugin_assets. See
the module docs for the URL scheme and caching policy.
Hashes are computed once, the first time the bundle is used.
Implementations§
Source§impl PluginAssets
impl PluginAssets
Sourcepub const fn from_files(
namespace: &'static str,
files: &'static [(&'static str, &'static [u8])],
) -> Self
pub const fn from_files( namespace: &'static str, files: &'static [(&'static str, &'static [u8])], ) -> Self
A bundle from an explicit list of (logical path, bytes) pairs.
Use this when the files are already include_bytes!/include_str!
constants, or when the crate does not enable embed-assets:
use autumn_web::assets::PluginAssets;
static ASSETS: PluginAssets = PluginAssets::from_files(
"charts",
&[("charts.js", b"console.log('charts');")],
);
assert!(ASSETS.url("charts.js").starts_with("/static/_plugins/charts/charts."));A logical path is relative (no leading /), uses / separators, and
has no .. or empty segments. Entries that break these rules, and
dotfiles, are skipped with a warning when the bundle is first used.
§Panics
Panics if namespace is empty, longer than 64 bytes, or contains
anything other than ASCII lowercase letters, digits, - and _. In a
static this is a compile-time error.
Sourcepub const fn from_dir(
namespace: &'static str,
dir: &'static Dir<'static>,
) -> Self
pub const fn from_dir( namespace: &'static str, dir: &'static Dir<'static>, ) -> Self
A bundle from a directory embedded with include_dir!. Every file in
the tree is included, except dotfiles. Prefer the
plugin_assets! macro, which embeds the
directory for you.
§Panics
Same namespace rules as from_files.
Sourcepub fn mount_path(&self) -> String
pub fn mount_path(&self) -> String
The URL path the bundle is served under, e.g. /static/_plugins/motion.
Sourcepub fn get(&self, logical_path: &str) -> Option<&PluginAsset>
pub fn get(&self, logical_path: &str) -> Option<&PluginAsset>
The file at logical_path, or None when the bundle has no such file.
Sourcepub fn iter(&self) -> impl Iterator<Item = &PluginAsset>
pub fn iter(&self) -> impl Iterator<Item = &PluginAsset>
Every file in the bundle, sorted by logical path.
Sourcepub fn url(&self, logical_path: &str) -> String
pub fn url(&self, logical_path: &str) -> String
The content-hashed URL of logical_path.
When the bundle has no such file this logs a warning and returns the
plain URL, which will 404. Use get to handle a
missing file yourself.
Sourcepub fn integrity(&self, logical_path: &str) -> Option<&str>
pub fn integrity(&self, logical_path: &str) -> Option<&str>
The sha384-<base64> Subresource Integrity hash of logical_path.
Sourcepub fn script_tag(&self, logical_path: &str) -> Markup
pub fn script_tag(&self, logical_path: &str) -> Markup
A <script> tag for logical_path, with the hashed src, integrity
and crossorigin="anonymous".
When the bundle has no such file this logs a warning and returns an HTML comment naming the file, so the gap shows in View Source.
Sourcepub fn deferred_script_tag(&self, logical_path: &str) -> Markup
pub fn deferred_script_tag(&self, logical_path: &str) -> Markup
Like script_tag, with the defer attribute.
Sourcepub fn stylesheet_tag(&self, logical_path: &str) -> Markup
pub fn stylesheet_tag(&self, logical_path: &str) -> Markup
A <link rel="stylesheet"> tag for logical_path, with the hashed
href, integrity and crossorigin="anonymous".
A missing file behaves as in script_tag.
Sourcepub fn router<S>(&'static self) -> Router<S>
pub fn router<S>(&'static self) -> Router<S>
A router serving every file at both its plain and its fingerprinted
URL, using absolute paths. Merge it yourself only for a custom setup;
AppBuilder::plugin_assets
mounts the bundle for you.
Sourcepub fn route_infos(&self) -> Vec<RouteInfo>
pub fn route_infos(&self) -> Vec<RouteInfo>
The bundle’s routes in the shape autumn routes lists them. Static
files are public, so every entry is classified
Public and
does not trip autumn routes audit.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for PluginAssets
impl RefUnwindSafe for PluginAssets
impl Send for PluginAssets
impl Sync for PluginAssets
impl Unpin for PluginAssets
impl UnsafeUnpin for PluginAssets
impl UnwindSafe for PluginAssets
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> AutumnCounterCaches for Twhere
T: 'static,
impl<T> AutumnCounterCaches for Twhere
T: 'static,
Source§const HAS_COUNTER_CACHES: bool = false
const HAS_COUNTER_CACHES: bool = false
Source§fn counter_caches() -> &'static [CounterCacheSpec<Self>]
fn counter_caches() -> &'static [CounterCacheSpec<Self>]
Source§impl<T> AutumnDependents for Twhere
T: ?Sized,
impl<T> AutumnDependents for Twhere
T: ?Sized,
Source§fn dependents() -> &'static [RuntimeDependentSpec]
fn dependents() -> &'static [RuntimeDependentSpec]
#[model] overrides via an inherent shadow when dependents exist.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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T, Conn> RunQueryDsl<Conn> for T
impl<T, Conn> RunQueryDsl<Conn> for T
Source§fn execute<'conn, 'query>(
self,
conn: &'conn mut Conn,
) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
fn execute<'conn, 'query>( self, conn: &'conn mut Conn, ) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
Source§fn load<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
fn load<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
Source§fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
Stream] with the returned rows. Read moreSource§fn get_result<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
fn get_result<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
Source§fn get_results<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
fn get_results<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
Vec with the affected rows. Read moreSource§impl<T> Scoped for T
impl<T> Scoped for T
Source§fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
ScopeQuery for this type. Resolves the
registered scope at .load() time, not here.