pub struct FormFieldValue<'a> { /* private fields */ }Expand description
A value from a form field.
This type represents a value from a form field, which can be either a text value or a multipart field (like a file upload). It provides methods to access the field’s metadata (name, filename, content type) and to convert the value into different formats.
Implementations§
Source§impl<'a> FormFieldValue<'a>
impl<'a> FormFieldValue<'a>
Sourcepub fn new_text<T: Into<String>>(text: T) -> Self
pub fn new_text<T: Into<String>>(text: T) -> Self
Creates a new text field value.
§Examples
use cot::form::FormFieldValue;
let value = FormFieldValue::new_text("hello");
assert_eq!(value.is_multipart(), false);
assert_eq!(value.filename(), None);
assert_eq!(value.content_type(), None);
assert_eq!(value.into_text().await?, "hello");Sourcepub fn filename(&self) -> Option<&str>
pub fn filename(&self) -> Option<&str>
Returns the filename of the field, if it has one.
Only multipart fields can have filenames. Text fields always return
None.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Returns the content type of the field, if it has one.
Only multipart fields can have content types. Text fields always return
None.
Sourcepub async fn into_bytes(self) -> Result<Bytes, FormFieldValueError>
pub async fn into_bytes(self) -> Result<Bytes, FormFieldValueError>
Converts the field value into bytes.
For text fields, this converts the text into bytes. For multipart fields, this reads the field’s content as bytes.
§Errors
This method can return an error if the field is a multipart field and the content cannot be read, for example, because of an I/O error.
§Examples
use bytes::Bytes;
use cot::form::FormFieldValue;
let text_value = FormFieldValue::new_text("hello");
assert_eq!(text_value.into_bytes().await?, Bytes::from("hello"));Sourcepub async fn into_text(self) -> Result<String, FormFieldValueError>
pub async fn into_text(self) -> Result<String, FormFieldValueError>
Converts the field value into text.
For text fields, this returns the text directly. For multipart fields, this reads the field’s content as text.
§Errors
This method can return an error if the field is a multipart field and the content cannot be read, for example, because of an I/O error.
§Examples
use cot::form::FormFieldValue;
let text_value = FormFieldValue::new_text("hello");
assert_eq!(text_value.into_text().await?, "hello");Sourcepub fn is_multipart(&self) -> bool
pub fn is_multipart(&self) -> bool
Returns whether this is a multipart field.
§Examples
use cot::form::FormFieldValue;
let text_value = FormFieldValue::new_text("hello");
assert!(!text_value.is_multipart());Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for FormFieldValue<'a>
impl<'a> !RefUnwindSafe for FormFieldValue<'a>
impl<'a> Send for FormFieldValue<'a>
impl<'a> Sync for FormFieldValue<'a>
impl<'a> Unpin for FormFieldValue<'a>
impl<'a> UnsafeUnpin for FormFieldValue<'a>
impl<'a> !UnwindSafe for FormFieldValue<'a>
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
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>
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>
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>
db only.