pub struct StaticFile { /* private fields */ }Expand description
A static file that can be served by the application.
This struct represents a static file that can be served by the application. It contains the file’s path, content, and MIME type. The MIME type is automatically detected based on the file extension.
§Examples
use bytes::Bytes;
use cot::static_files::StaticFile;
use cot::{App, static_files};
pub struct ExampleApp;
// Project structure:
// .
// ├── Cargo.toml
// └── static
// └── test
// └── test.txt
impl App for ExampleApp {
fn name(&self) -> &str {
"test_app"
}
fn static_files(&self) -> Vec<StaticFile> {
static_files!("test/test.txt")
}
}Implementations§
Source§impl StaticFile
impl StaticFile
Sourcepub fn new<Path, Content>(path: Path, content: Content) -> Self
pub fn new<Path, Content>(path: Path, content: Content) -> Self
Creates a new StaticFile instance.
The MIME type is automatically detected based on the file extension.
If the file extension is not recognized, it defaults to
application/octet-stream.
Instead of using this constructor, it’s typically more convenient
to use the static_files! macro.
§Examples
use cot::static_files::StaticFile;
let file = StaticFile::new("style.css", "body { color: red; }");Trait Implementations§
Source§impl Clone for StaticFile
impl Clone for StaticFile
Source§fn clone(&self) -> StaticFile
fn clone(&self) -> StaticFile
Returns a duplicate 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 StaticFile
impl Debug for StaticFile
Source§impl Hash for StaticFile
impl Hash for StaticFile
Source§impl PartialEq for StaticFile
impl PartialEq for StaticFile
impl Eq for StaticFile
impl StructuralPartialEq for StaticFile
Auto Trait Implementations§
impl !Freeze for StaticFile
impl RefUnwindSafe for StaticFile
impl Send for StaticFile
impl Sync for StaticFile
impl Unpin for StaticFile
impl UnwindSafe for StaticFile
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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> 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>
Converts
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>
Converts
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 moreSource§impl<T> IntoField<Auto<T>> for T
impl<T> IntoField<Auto<T>> for T
Source§fn into_field(self) -> Auto<T>
fn into_field(self) -> Auto<T>
Available on crate feature
db only.Converts the type to the field type.