pub struct FileMetadata {Show 15 fields
pub url: Option<Url>,
pub mime_type: Option<String>,
pub hash: Option<[u8; 32]>,
pub original_hash: Option<[u8; 32]>,
pub size: Option<u64>,
pub dim: Option<ImageDimensions>,
pub magnet: Option<String>,
pub torrent_infohash: Option<String>,
pub blurhash: Option<String>,
pub thumb: Option<FileVariant>,
pub preview_image: Option<FileVariant>,
pub summary: Option<String>,
pub alt: Option<String>,
pub fallback_urls: Vec<Url>,
pub service: Option<String>,
}Expand description
Typed bundle of every NIP-94 field.
Build incrementally with Self::new + the chainable setters,
or hydrate from a wire event with Self::from_event.
Fields§
§url: Option<Url>Download URL (url tag — required).
mime_type: Option<String>MIME type (m tag — required).
hash: Option<[u8; 32]>SHA-256 of the served bytes (x tag — required).
original_hash: Option<[u8; 32]>SHA-256 of the original bytes before any server-side
transformation (ox tag).
size: Option<u64>File size in bytes (size tag).
dim: Option<ImageDimensions>Pixel dimensions (dim tag).
magnet: Option<String>Magnet URI (magnet tag).
torrent_infohash: Option<String>Torrent infohash (i tag).
blurhash: Option<String>Blurhash placeholder (blurhash tag).
thumb: Option<FileVariant>Thumbnail variant (thumb tag).
preview_image: Option<FileVariant>Preview image variant (image tag).
summary: Option<String>Text excerpt (summary tag).
alt: Option<String>Accessibility description (alt tag).
fallback_urls: Vec<Url>Zero or more fallback download URLs (fallback tags).
service: Option<String>Serving-service identifier such as nip96 (service tag).
Implementations§
Source§impl FileMetadata
impl FileMetadata
Sourcepub fn new(url: Url, mime_type: impl Into<String>, hash: [u8; 32]) -> Self
pub fn new(url: Url, mime_type: impl Into<String>, hash: [u8; 32]) -> Self
Construct with the three required fields.
Sourcepub const fn original_hash(self, hash: [u8; 32]) -> Self
pub const fn original_hash(self, hash: [u8; 32]) -> Self
Set Self::original_hash.
Sourcepub const fn size(self, size: u64) -> Self
pub const fn size(self, size: u64) -> Self
Set Self::size.
Sourcepub const fn dim(self, dim: ImageDimensions) -> Self
pub const fn dim(self, dim: ImageDimensions) -> Self
Set Self::dim.
Sourcepub fn magnet(self, magnet: impl Into<String>) -> Self
pub fn magnet(self, magnet: impl Into<String>) -> Self
Set Self::magnet.
Sourcepub fn torrent_infohash(self, infohash: impl Into<String>) -> Self
pub fn torrent_infohash(self, infohash: impl Into<String>) -> Self
Sourcepub fn blurhash(self, blurhash: impl Into<String>) -> Self
pub fn blurhash(self, blurhash: impl Into<String>) -> Self
Set Self::blurhash.
Sourcepub fn thumb(self, thumb: FileVariant) -> Self
pub fn thumb(self, thumb: FileVariant) -> Self
Set Self::thumb.
Sourcepub fn preview_image(self, image: FileVariant) -> Self
pub fn preview_image(self, image: FileVariant) -> Self
Set Self::preview_image.
Sourcepub fn summary(self, summary: impl Into<String>) -> Self
pub fn summary(self, summary: impl Into<String>) -> Self
Set Self::summary.
Sourcepub fn service(self, service: impl Into<String>) -> Self
pub fn service(self, service: impl Into<String>) -> Self
Set Self::service.
Sourcepub fn from_event(event: &Event) -> Result<Self, FileMetadataError>
pub fn from_event(event: &Event) -> Result<Self, FileMetadataError>
Parse a kind: 1063 event back into a typed bundle.
§Errors
FileMetadataError::WrongKindfor any other kind.FileMetadataError::MissingUrl/MissingMimeType/MissingHashwhen the corresponding required tag is absent.FileMetadataError::InvalidUrl/InvalidHash/InvalidSize/InvalidDimwhen the value is present but malformed.
Parse a tag list (without requiring a wrapping event). Useful when callers already know the event kind matches and only want the metadata reconstruction.
§Errors
See Self::from_event.
Materialise the bundle into a Vec<Tag> ready for use with
EventBuilder::tag / EventBuilder::tags. Required
fields must be set; missing required fields produce an
Err(FileMetadataError::Missing*) so authoring stays
symmetric with reading.
§Errors
Returns the corresponding Missing* error when a required
field is unset.
Trait Implementations§
Source§impl Clone for FileMetadata
impl Clone for FileMetadata
Source§fn clone(&self) -> FileMetadata
fn clone(&self) -> FileMetadata
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 FileMetadata
impl Debug for FileMetadata
Source§impl Default for FileMetadata
impl Default for FileMetadata
Source§fn default() -> FileMetadata
fn default() -> FileMetadata
impl Eq for FileMetadata
Source§impl PartialEq for FileMetadata
impl PartialEq for FileMetadata
impl StructuralPartialEq for FileMetadata
Auto Trait Implementations§
impl Freeze for FileMetadata
impl RefUnwindSafe for FileMetadata
impl Send for FileMetadata
impl Sync for FileMetadata
impl Unpin for FileMetadata
impl UnsafeUnpin for FileMetadata
impl UnwindSafe for FileMetadata
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,
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.