[][src]Struct imgix::url::Url

pub struct Url { /* fields omitted */ }

Primary structure used to generate imgix URLs.

An imgix URL is comprised of four components:

  • scheme - the scheme being used (https by default).
  • domain - the domain, i.e. example.domain.net.
  • path - the path to the image file.
  • query - the query string constructed from params.
└─┬─┘                  └──────┬───────┘ └────┬────┘
scheme                      path           params

This structure is meant to be a crate primitive that crate users and contributors can use to build on. This is part of the reason why many of the building functions can panic. They panic to try to ensure invalid urls are never constructed. This is to provide higher-level structures certain guarantees about the representation of a Url.


impl Url[src]

pub fn new(domain: &str) -> Self[src]

Construct a new Url given a domain.


This constructor will fail if the domain is an empty string.

pub fn domain(self, d: &str) -> Self[src]

Set the domain value (i.e. "example.domain.net").


This method panics if passed an empty string.

pub fn path(self, p: &str) -> Self[src]

Set the path value to the image file (i.e. 'image/path.png').


This method panics if passed an empty string.

pub fn param(self, k: &'static str, v: &'static str) -> Self[src]

Set an arbitrary key-value parameter (i.e. k='w', v='100' or k='fit', v='crop').


use imgix::Url;
let url = Url::new("example.domain.net").param("w", "320").path("test").lib("");
let right = "https://example.domain.net/test?w=320";
assert_eq!(url.join(), "https://example.domain.net/test?w=320")


This method panics if any key k or any value v is an empty string, where k and v represent string literals.

pub fn params(self, p: &[(&'static str, &'static str)]) -> Self[src]

Set an arbitrary number of key-value parameters.


use imgix::Url;

let url = Url::new("example.domain.net")
    .params(&[("w", "320"), ("h", "640"), ("fit", "crop")]);

let right = "https://example.domain.net/test?w=320&h=640&fit=crop";
assert_eq!(url.join(), right);


This method panics if any key k or any value v is an empty string.

pub fn lib(self, l: &str) -> Self[src]

Set the library version explicitly, see Url::ix() for the implicit default.

The Url's lib value can be set to any String by passing the desired string literal. If the lib is a valid ix-lib parameter if will be considered on the server. However, if an invalid lib-parameter is passed, e.g. "rust-is-cool", it will be ignored (appreciated ;) but ignored).


use imgix::{lib_version, Scheme, Url};

const DOMAIN: &str = "example.domain.net";
const PATH: &str = "image.png";

let url = Url::new(DOMAIN)

let right = format!(
    scheme = Scheme::Https,
    domain = DOMAIN,
    path = PATH,
    lib = lib_version()

assert_eq!(url.join(), right);

let url = url.lib("rust-is-cool");
assert_ne!(url.join(), right);

pub fn token(self, t: &str) -> Self[src]

Set the signing token. TODO: Test token post md5 implementation.

pub fn scheme(self, s: Scheme) -> Self[src]

pub fn ix(self) -> Self[src]

pub fn join(&self) -> String[src]

Join the components of a Url (i.e. scheme + domain + path + params) where the resulting string has the following form:


This function will only join the components of a Url if a path has been specified.


This function will panic if the image path has not been specified. (i.e. if the path is None). This is to ensure that a Url is joined if it is in a valid state.

pub fn join_params(p: &[(&'static str, &'static str)]) -> String[src]

Join a list of key-value parameter pairs.

This associated function joins a list of key-value pairs. It is internal to Url and doesn't do much validation. This is to avoid duplicate validations as these parameters are valid at the time of construction.



This function panics if any key k or any value v is an empty string.

pub fn get_scheme(&self) -> &Scheme[src]

pub fn get_domain(&self) -> &str[src]

pub fn get_lib(&self) -> &str[src]

pub fn get_params(&self) -> &[(&'static str, &'static str)][src]

pub fn get_path(&self) -> &str[src]

pub fn get_token(&self) -> &str[src]

pub fn has_params(&self) -> bool[src]

pub fn to_srcset(&self) -> String[src]

Trait Implementations

impl Debug for Url[src]

impl Default for Url[src]

fn default() -> Self[src]

By default a URL is created with its scheme set to Scheme::Https and the lib value set to the version specified in this library's Cargo.toml

impl From<Url> for SourceSet[src]

Auto Trait Implementations

impl RefUnwindSafe for Url

impl Send for Url

impl Sync for Url

impl Unpin for Url

impl UnwindSafe for Url

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.