diff --git a/http-ws/src/codec.rs b/http-ws/src/codec.rs index d81c45a4..dc52f8d3 100644 --- a/http-ws/src/codec.rs +++ b/http-ws/src/codec.rs @@ -67,6 +67,12 @@ impl Flags { } } +impl Default for Codec { + fn default() -> Self { + unimplemented!("please use Codec::new") + } +} + impl Codec { /// Create new WebSocket frames decoder. pub const fn new() -> Codec { diff --git a/http/src/builder.rs b/http/src/builder.rs index a3c58925..de1f9b4f 100644 --- a/http/src/builder.rs +++ b/http/src/builder.rs @@ -40,6 +40,20 @@ pub struct HttpServiceBuilder< pub(crate) _body: PhantomData, } +impl Default + for HttpServiceBuilder< + marker::Http, + net::Stream, + tls::NoOpTlsAcceptorBuilder, + DEFAULT_HEADER_LIMIT, + DEFAULT_READ_BUF_LIMIT, + DEFAULT_WRITE_BUF_LIMIT, + > +{ + fn default() -> Self { + unimplemented!("please use HttpServiceBuilder::new") + } +} impl HttpServiceBuilder< marker::Http, diff --git a/http/src/util/middleware/context.rs b/http/src/util/middleware/context.rs index 8058d438..0476fe85 100644 --- a/http/src/util/middleware/context.rs +++ b/http/src/util/middleware/context.rs @@ -186,7 +186,7 @@ mod router_impl { where I: PathGen, { - fn path_gen(&mut self, prefix: String) -> String { + fn path_gen(&mut self, prefix: &str) -> String { self.0.path_gen(prefix) } } diff --git a/http/src/util/service/router.rs b/http/src/util/service/router.rs index 04126044..76e8c670 100644 --- a/http/src/util/service/router.rs +++ b/http/src/util/service/router.rs @@ -54,7 +54,7 @@ impl Router { F::Response: Service, Req: IntoObject, Arg, Object = Obj>, { - let path = builder.path_gen(String::from(path)); + let path = builder.path_gen(path); assert!(self .routes .insert(path, Req::into_object(F::route_gen(builder))) @@ -141,8 +141,8 @@ pub trait PathGen { /// path generator. /// /// default to passthrough of original prefix path. - fn path_gen(&mut self, prefix: String) -> String { - prefix + fn path_gen(&mut self, prefix: &str) -> String { + String::from(prefix) } } @@ -162,7 +162,8 @@ impl PathGen for Router where Obj: PathGen, { - fn path_gen(&mut self, mut path: String) -> String { + fn path_gen(&mut self, path: &str) -> String { + let mut path = String::from(path); if path.ends_with("/*") { path.pop(); } @@ -171,12 +172,11 @@ where path.pop(); } - if let Some(prefix) = self.prefix.replace(path.len()) { - self.prefix = Some(path.len() + prefix); - } + let prefix = self.prefix.get_or_insert(0); + *prefix += path.len(); self.routes.iter_mut().for_each(|(_, v)| { - v.path_gen(path.clone()); + v.path_gen(path.as_str()); }); path.push_str("/*"); @@ -230,7 +230,7 @@ impl PathGen for PipelineT where F: PathGen, { - fn path_gen(&mut self, prefix: String) -> String { + fn path_gen(&mut self, prefix: &str) -> String { self.first.path_gen(prefix) } } @@ -253,7 +253,7 @@ impl PathGen for RouterMapErr where S: PathGen, { - fn path_gen(&mut self, prefix: String) -> String { + fn path_gen(&mut self, prefix: &str) -> String { self.0.path_gen(prefix) } } @@ -324,7 +324,7 @@ mod object { pub struct RouteObject(pub Box + Send + Sync>); impl PathGen for RouteObject { - fn path_gen(&mut self, prefix: String) -> String { + fn path_gen(&mut self, prefix: &str) -> String { self.0.path_gen(prefix) } } @@ -362,7 +362,7 @@ where where T: PathGen, { - fn path_gen(&mut self, prefix: String) -> String { + fn path_gen(&mut self, prefix: &str) -> String { self.0.path_gen(prefix) } } diff --git a/router/src/router.rs b/router/src/router.rs index 0b222fac..331b22fb 100644 --- a/router/src/router.rs +++ b/router/src/router.rs @@ -9,6 +9,12 @@ pub struct Router { root: Node, } +impl Default for Router { + fn default() -> Self { + unimplemented!("please use Router::new"); + } +} + impl Router { /// Construct a new router. pub const fn new() -> Self { diff --git a/service/src/middleware/group.rs b/service/src/middleware/group.rs index 259f6a25..fe726f7d 100644 --- a/service/src/middleware/group.rs +++ b/service/src/middleware/group.rs @@ -26,6 +26,12 @@ use crate::service::Service; /// ``` pub struct Group(PhantomData); +impl Default for Group { + fn default() -> Self { + unimplemented!("please use Group::new"); + } +} + impl Group { pub const fn new() -> Self { Self(PhantomData) diff --git a/unsafe_collection/src/bound_queue/stack.rs b/unsafe_collection/src/bound_queue/stack.rs index 6b70be6a..6a2ab92a 100644 --- a/unsafe_collection/src/bound_queue/stack.rs +++ b/unsafe_collection/src/bound_queue/stack.rs @@ -8,6 +8,12 @@ pub struct StackQueue { inner: Bounded<[MaybeUninit; N]>, } +impl Default for StackQueue { + fn default() -> Self { + unimplemented!("please use StackQueue::new"); + } +} + impl StackQueue { #[inline] pub const fn new() -> Self { diff --git a/unsafe_collection/src/small_str.rs b/unsafe_collection/src/small_str.rs index 32e4b392..40141395 100644 --- a/unsafe_collection/src/small_str.rs +++ b/unsafe_collection/src/small_str.rs @@ -217,6 +217,12 @@ pub struct SmallBoxedStr { inner: Inner, } +impl Default for SmallBoxedStr { + fn default() -> Self { + unimplemented!("please use SmallBoxedStr::new") + } +} + impl SmallBoxedStr { #[inline] pub const fn new() -> Self { diff --git a/web/src/app/mod.rs b/web/src/app/mod.rs index e0c5f854..36a7f791 100644 --- a/web/src/app/mod.rs +++ b/web/src/app/mod.rs @@ -519,7 +519,7 @@ impl PathGen for App where R: PathGen, { - fn path_gen(&mut self, prefix: String) -> String { + fn path_gen(&mut self, prefix: &str) -> String { self.router.path_gen(prefix) } } diff --git a/web/src/app/object.rs b/web/src/app/object.rs index d5624b75..f473efa9 100644 --- a/web/src/app/object.rs +++ b/web/src/app/object.rs @@ -23,7 +23,7 @@ where where I: PathGen, { - fn path_gen(&mut self, prefix: String) -> String { + fn path_gen(&mut self, prefix: &str) -> String { self.0.path_gen(prefix) } } diff --git a/web/src/app/router.rs b/web/src/app/router.rs index 2e4c2e06..242cd82a 100644 --- a/web/src/app/router.rs +++ b/web/src/app/router.rs @@ -37,7 +37,7 @@ impl PathGen for AppRouter where Router: PathGen, { - fn path_gen(&mut self, prefix: String) -> String { + fn path_gen(&mut self, prefix: &str) -> String { self.0.path_gen(prefix) } } diff --git a/web/src/service/file.rs b/web/src/service/file.rs index d60d87bb..2c56b264 100644 --- a/web/src/service/file.rs +++ b/web/src/service/file.rs @@ -39,7 +39,8 @@ impl ServeDir { } impl PathGen for ServeDir { - fn path_gen(&mut self, mut prefix: String) -> String { + fn path_gen(&mut self, prefix: &str) -> String { + let mut prefix = String::from(prefix); if prefix.ends_with('/') { prefix.pop(); }