#[non_exhaustive]pub struct SignedWatermarkParams {
pub url: String,
pub position: Option<String>,
pub opacity: Option<u8>,
pub margin: Option<u32>,
}Expand description
Builds a signed public transform URL for the server adapter.
The resulting URL targets either GET /images/by-path or GET /images/by-url depending on
source. base_url must be an absolute http or https URL that points at the externally
visible server origin. The helper applies the same canonical query and HMAC-SHA256 signature
scheme that the server adapter verifies at request time.
The helper serializes only explicitly requested transform options and omits fields that would resolve to the documented defaults on the server side.
§Errors
Returns an error string when base_url is not an absolute http or https URL, when the
visible authority cannot be determined, or when the HMAC state cannot be initialized.
§Examples
use truss::{sign_public_url, SignedUrlSource};
use truss::{MediaType, TransformOptions};
let mut options = TransformOptions::default();
options.format = Some(MediaType::Jpeg);
let url = sign_public_url(
"https://cdn.example.com",
SignedUrlSource::Path {
path: "/image.png".to_string(),
version: None,
},
&options,
"public-dev",
"secret-value",
4_102_444_800,
None,
None,
)
.unwrap();
assert!(url.starts_with("https://cdn.example.com/images/by-path?"));
assert!(url.contains("keyId=public-dev"));
assert!(url.contains("signature="));Optional watermark parameters for signed URL generation.
Each field other than the URL is None when the caller does not name it, and the server
then applies the same default it applies to a watermark from any other adapter.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.url: StringThe URL the watermark image is fetched from.
position: Option<String>Where to place the watermark, as the name the vocabulary uses.
opacity: Option<u8>Opacity of the watermark, 1 to 100.
margin: Option<u32>Margin in pixels from the nearest edge.
Implementations§
Source§impl SignedWatermarkParams
impl SignedWatermarkParams
Sourcepub fn new(url: impl Into<String>) -> Self
pub fn new(url: impl Into<String>) -> Self
Names the watermark image and leaves every other parameter to the server’s default.
A caller assigns the rest afterwards. The struct is #[non_exhaustive], so a
parameter the watermark vocabulary gains later is a minor change rather than a
breaking one.
Trait Implementations§
Source§impl Debug for SignedWatermarkParams
impl Debug for SignedWatermarkParams
Source§impl Default for SignedWatermarkParams
impl Default for SignedWatermarkParams
Source§fn default() -> SignedWatermarkParams
fn default() -> SignedWatermarkParams
Auto Trait Implementations§
impl Freeze for SignedWatermarkParams
impl RefUnwindSafe for SignedWatermarkParams
impl Send for SignedWatermarkParams
impl Sync for SignedWatermarkParams
impl Unpin for SignedWatermarkParams
impl UnsafeUnpin for SignedWatermarkParams
impl UnwindSafe for SignedWatermarkParams
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more