pub struct Attachment {
pub key: String,
pub filename: String,
pub content_type: String,
pub size: i64,
}Expand description
A stored file, as saved with its record in four columns.
The columns of an attachment named avatar are avatar_key,
avatar_filename, avatar_content_type and avatar_size (NULL-able for
an optional attachment). store returns it, columns /
column_changes bind it, and it deserializes from a row whose columns
are aliased to key, filename, content_type and size (generated
models expose it as photo.image()). It also serializes to JSON as is.
§Examples
use ocre::storage::Attachment;
let avatar = Attachment {
key: "posts/avatar/2u1Vd0zJ8sQqS6rJq0rVmA".into(),
filename: "me.png".into(),
content_type: "image/png".into(),
size: 2048,
};
assert_eq!(avatar.human_size(), "2 KB");
let row = serde_json::json!({ "key": "k", "filename": "a.pdf", "content_type": "application/pdf", "size": 10 });
let from_row: Attachment = serde_json::from_value(row).unwrap();
assert_eq!(from_row.filename, "a.pdf");Fields§
§key: StringObject key in the R2 bucket: <prefix>/<22 random URL-safe characters>.
filename: StringThe uploader’s file name, without directories or control characters.
content_type: StringContent type, lowercase and without parameters (image/png).
size: i64Size in bytes.
Implementations§
Source§impl Attachment
impl Attachment
Sourcepub fn human_size(&self) -> String
pub fn human_size(&self) -> String
Formats the size for people with human_size: 512 bytes, 2 KB, 1.5 MB.
A negative size (only possible from a hand-edited row) reads 0 bytes.
§Examples
let file = ocre::storage::Attachment { size: 1536 * 1024, ..Default::default() };
assert_eq!(file.human_size(), "1.5 MB");Trait Implementations§
Source§impl Clone for Attachment
impl Clone for Attachment
Source§fn clone(&self) -> Attachment
fn clone(&self) -> Attachment
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Attachment
impl Debug for Attachment
Source§impl Default for Attachment
impl Default for Attachment
Source§fn default() -> Attachment
fn default() -> Attachment
Source§impl<'de> Deserialize<'de> for Attachment
impl<'de> Deserialize<'de> for Attachment
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>,
impl Eq for Attachment
Source§impl PartialEq for Attachment
impl PartialEq for Attachment
Source§fn eq(&self, other: &Attachment) -> bool
fn eq(&self, other: &Attachment) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for Attachment
impl Serialize for Attachment
impl StructuralPartialEq for Attachment
Auto Trait Implementations§
impl Freeze for Attachment
impl RefUnwindSafe for Attachment
impl Send for Attachment
impl Sync for Attachment
impl Unpin for Attachment
impl UnsafeUnpin for Attachment
impl UnwindSafe for Attachment
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.