diff --git a/README.md b/README.md new file mode 100644 index 0000000..78edaa9 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Thumbor for rust + +## Usage + +```rust +use thumbor::Server; + +let server = Server::new_secured("http://localhost:8888", "my-security-key"); + +let builder = server.url_builder() + .resize((300, 200)) + .smart(true) + .build(); + +let url = builder.build("/path/to/my/image.jpg"); +``` diff --git a/src/server.rs b/src/server.rs index 9dd6cb2..26a9961 100644 --- a/src/server.rs +++ b/src/server.rs @@ -17,6 +17,12 @@ impl From for Security { } } +/// ``` +/// use thumbor::Server; +/// +/// let server = Server::new_secured("http://localhost:8888", "my-security-key"); +/// let server = Server::new_unsafe("http://localhost:8888"); // Don't use this in production ! +/// ``` #[derive(Default, Clone)] pub struct Server { pub origin: String, diff --git a/src/settings/filter.rs b/src/settings/filter.rs index 55c5030..5edaccd 100644 --- a/src/settings/filter.rs +++ b/src/settings/filter.rs @@ -108,10 +108,9 @@ pub enum Filter { }, } -impl fmt::Display for Filter { - #[allow(clippy::too_many_lines)] - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let args = match self { +impl Filter { + fn args(&self) -> Vec { + match self { Filter::AutoJPG | Filter::Cover | Filter::Equalize @@ -216,13 +215,18 @@ impl fmt::Display for Filter { } args } - }; + } + } +} +impl fmt::Display for Filter { + #[allow(clippy::too_many_lines)] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let name = match self { Filter::Custom { name, .. } => name, _ => self.as_ref(), }; - write!(f, "{name}({})", args.join(",")) + write!(f, "{name}({})", self.args().join(",")) } }