pub struct Params(/* private fields */);Expand description
Request parameters as text, from ctx.params(). Keys repeat-free; the
last value for a key wins (so a hidden false before a checkbox works).
Implementations§
Source§impl Params
impl Params
Sourcepub fn require(&self, key: &str) -> Result<Params>
pub fn require(&self, key: &str) -> Result<Params>
The params nested under key, as Rails’ params.require(:post): a
JSON object ({"post": {"title": "…"}}) or form fields named
post[title]. Missing or empty is a 400 Bad Request.
As Rails’ default wrap_parameters, in a controller’s action a JSON
body without the controller’s own key (post for Posts) is read as
though nested under it: {"title": "…"} works too. When a model has
that name, only its attributes are ({"foo": 1} is then missing).
Sourcepub fn fetch(&self, key: &str) -> Result<Params>
pub fn fetch(&self, key: &str) -> Result<Params>
The params nested under key, as Rails’ params.fetch(:answer):
like require, but present and empty is fine (an
action that only looks for an optional upload, say). Only a missing
key is a 400 Bad Request; in a controller’s action, a JSON body is
always wrapped under its key, so there it’s never missing.
pub fn get(&self, name: &str) -> Option<&str>
Sourcepub fn value(&self, name: &str) -> &str
pub fn value(&self, name: &str) -> &str
A param as text, "" when it’s missing: params[:post_id] in
.glacier, as Rails’ params[:post_id].
pub fn contains(&self, name: &str) -> bool
pub fn insert(&mut self, name: impl Into<String>, value: impl Into<String>)
Sourcepub fn list(&self, name: &str) -> Vec<String>
pub fn list(&self, name: &str) -> Vec<String>
A list param, as Rails reads params[:ids]: every ids[]=1&ids[]=2
value, a JSON array’s elements ({"ids": [1, 2]}), or a single
ids=1. Empty when it’s missing.
pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>
Trait Implementations§
Source§impl<M: Model> From<Params> for Changeset<M>
Post::create(ctx.params()): casts the model’s permitted fields.
impl<M: Model> From<Params> for Changeset<M>
Post::create(ctx.params()): casts the model’s permitted fields.
Source§impl Index<&str> for Params
params["post_id"] (in .glacier, params[:post_id]): a param as
text, or "" when it’s missing, as Rails’ params[:post_id] is nil.
impl Index<&str> for Params
params["post_id"] (in .glacier, params[:post_id]): a param as
text, or "" when it’s missing, as Rails’ params[:post_id] is nil.
impl StructuralPartialEq for Params
Auto Trait Implementations§
impl Freeze for Params
impl RefUnwindSafe for Params
impl Send for Params
impl Sync for Params
impl Unpin for Params
impl UnsafeUnpin for Params
impl UnwindSafe for Params
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<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 more