pub struct Client {
pub key: String,
}Fields
key: StringImplementations
sourceimpl Client
impl Client
pub fn new(key: String) -> Self
sourcepub fn from_file(&self, path: &str) -> Result<Source, TinifyException>
pub fn from_file(&self, path: &str) -> Result<Source, TinifyException>
Choose a file to compress.
Examples
use tinify::{Tinify, TinifyException};
fn main() -> Result<(), TinifyException> {
let key = "tinify api key";
let optimized = Tinify::new()
.set_key(key)
.get_client()?
.from_file("./unoptimized.png")?
.to_file("./optimized.png");
Ok(())
}sourcepub fn from_buffer(&self, buffer: &[u8]) -> Result<Source, TinifyException>
pub fn from_buffer(&self, buffer: &[u8]) -> Result<Source, TinifyException>
Choose a buffer to compress.
Examples
use tinify::{Tinify, TinifyException};
use std::fs;
fn main() -> Result<(), TinifyException> {
let key = "tinify api key";
let bytes = fs::read("./unoptimized.png").unwrap();
let buffer = Tinify::new()
.set_key(key)
.get_client()?
.from_buffer(&bytes)?
.to_buffer();
let save = fs::write("./optimized.png", buffer).unwrap();
Ok(())
}sourcepub fn from_url(&self, url: &str) -> Result<Source, TinifyException>
pub fn from_url(&self, url: &str) -> Result<Source, TinifyException>
Choose an url file to compress.
Examples
use tinify::{Tinify, TinifyException};
fn main() -> Result<(), TinifyException> {
let key = "tinify api key";
let optimized = Tinify::new()
.set_key(key)
.get_client()?
.from_url("https://tinypng.com/images/panda-happy.png")?
.to_file("./optimized.png");
Ok(())
}Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnwindSafe for Client
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more