Struct tinify::Client

source ·
pub struct Client {
    pub key: String,
}

Fields

key: String

Implementations

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(())
}

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(())
}

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more