mirror of https://github.com/rwf2/Rocket.git
Use 'UriPart::Kind' to avoid unreachable match arms.
This commit is contained in:
parent
7628546ca2
commit
a3946377f7
|
@ -1,6 +1,6 @@
|
|||
|
||||
use devise::{*, ext::SpanDiagnosticExt};
|
||||
use rocket_http::uri::UriPart;
|
||||
use rocket_http::uri;
|
||||
|
||||
use crate::exports::*;
|
||||
use crate::derive::form_field::FieldExt;
|
||||
|
@ -129,11 +129,10 @@ pub fn derive_uri_display_path(input: proc_macro::TokenStream) -> TokenStream {
|
|||
ts.into()
|
||||
}
|
||||
|
||||
fn from_uri_param<P: UriPart>(input: proc_macro::TokenStream, ty: TokenStream) -> TokenStream {
|
||||
let part = match P::DELIMITER {
|
||||
'/' => quote!(#_uri::Path),
|
||||
'&' => quote!(#_uri::Query),
|
||||
_ => unreachable!("sealed trait with path/query")
|
||||
fn from_uri_param<P: uri::UriPart>(input: proc_macro::TokenStream, ty: TokenStream) -> TokenStream {
|
||||
let part = match P::KIND {
|
||||
uri::Kind::Path => quote!(#_uri::Path),
|
||||
uri::Kind::Query => quote!(#_uri::Query),
|
||||
};
|
||||
|
||||
let ty: syn::Type = syn::parse2(ty).expect("valid type");
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::marker::PhantomData;
|
|||
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::uri::{UriPart, Path, Query, UriDisplay, Origin};
|
||||
use crate::uri::{UriPart, Path, Query, UriDisplay, Origin, Kind};
|
||||
|
||||
/// A struct used to format strings for [`UriDisplay`].
|
||||
///
|
||||
|
@ -214,16 +214,12 @@ impl<'i, P: UriPart> Formatter<'i, P> {
|
|||
// cases for both Path and Query, and doing it this way allows us to
|
||||
// keep the uri part generic _generic_ in other implementations that use
|
||||
// `write_raw`.
|
||||
if self.fresh && P::DELIMITER == '/' {
|
||||
if self.previous {
|
||||
self.inner.write_char(P::DELIMITER)?;
|
||||
}
|
||||
} else if self.fresh && P::DELIMITER == '&' {
|
||||
if self.fresh {
|
||||
if self.previous {
|
||||
self.inner.write_char(P::DELIMITER)?;
|
||||
}
|
||||
|
||||
if !self.prefixes.is_empty() {
|
||||
if P::KIND == Kind::Query && !self.prefixes.is_empty() {
|
||||
for (i, prefix) in self.prefixes.iter().enumerate() {
|
||||
self.inner.write_str(prefix)?;
|
||||
if i < self.prefixes.len() - 1 {
|
||||
|
|
|
@ -3,7 +3,8 @@ use std::borrow::Cow;
|
|||
|
||||
use crate::ext::IntoOwned;
|
||||
use crate::parse::{Indexed, Extent, IndexedStr};
|
||||
use crate::uri::{as_utf8_unchecked, Error, UriPart, Query, Path, Segments, QuerySegments};
|
||||
use crate::uri::{self, UriPart, Query, Path};
|
||||
use crate::uri::{Error, Segments, QuerySegments, as_utf8_unchecked};
|
||||
use crate::RawStr;
|
||||
|
||||
use state::Storage;
|
||||
|
@ -120,10 +121,9 @@ fn decode_to_indexed_str<P: UriPart>(
|
|||
value: &RawStr,
|
||||
(indexed, source): (&IndexedStr<'_>, &RawStr)
|
||||
) -> IndexedStr<'static> {
|
||||
let decoded = match P::DELIMITER {
|
||||
Query::DELIMITER => value.url_decode_lossy(),
|
||||
Path::DELIMITER => value.percent_decode_lossy(),
|
||||
_ => unreachable!("sealed trait admits only path and query")
|
||||
let decoded = match P::KIND {
|
||||
uri::Kind::Path => value.percent_decode_lossy(),
|
||||
uri::Kind::Query => value.url_decode_lossy(),
|
||||
};
|
||||
|
||||
match decoded {
|
||||
|
|
Loading…
Reference in New Issue