pub enum Referrer {
Address {
address: String,
},
Code {
code: String,
},
}Expand description
Partner referral tracking information.
The upstream CoW Protocol app-data schema for referrer changed
shape between v1.13.0 and v1.14.0:
| Schema version | Shape | Pattern |
|---|---|---|
| v0.1.0 – v1.13.0 | { "address": "0x…" } (partner Ethereum address) | ^0x[a-fA-F0-9]{40}$ |
| v1.14.0+ | { "code": "ABCDE" } (affiliate code, uppercase) | ^[A-Z0-9_-]{5,20}$ |
Both forms are modelled as variants of this enum with
#[serde(untagged)], so a single Referrer value deserialises
correctly from either shape and serialises back into the same shape.
Runtime schema validation via [super::schema::validate] dispatches
on the document’s declared version and picks the matching bundled
schema, so an Address-flavoured referrer must accompany a
v1.13.0-or-earlier document and a Code-flavoured one a v1.14.0+
document.
§Construction
Prefer the dedicated constructors Referrer::address and
Referrer::code; Referrer::new is kept as a deprecated alias
for the address form so existing v1.13.0-era code keeps compiling.
Variants§
Address
Legacy form used by schema versions up to and including v1.13.0.
Code
Current form used by schema v1.14.0 and later.
Implementations§
Source§impl Referrer
impl Referrer
Sourcepub fn address(address: impl Into<String>) -> Self
pub fn address(address: impl Into<String>) -> Self
Construct an address-flavoured referrer (schema v0.1.0 – v1.13.0).
The address is stored verbatim; callers are responsible for
passing a well-formed 0x-prefixed 40-character hex string.
Runtime schema validation under v1.13.0 rejects non-conforming
values.
§Example
use cow_app_data::Referrer;
let r = Referrer::address("0xb6BAd41ae76A11D10f7b0E664C5007b908bC77C9");
assert_eq!(r.as_address(), Some("0xb6BAd41ae76A11D10f7b0E664C5007b908bC77C9"));
assert_eq!(r.as_code(), None);Sourcepub fn code(code: impl Into<String>) -> Self
pub fn code(code: impl Into<String>) -> Self
Construct a code-flavoured referrer (schema v1.14.0+).
The code is stored verbatim; callers are responsible for
matching the upstream regex ^[A-Z0-9_-]{5,20}$. Runtime schema
validation under v1.14.0 rejects non-conforming values.
§Example
use cow_app_data::Referrer;
let r = Referrer::code("COWRS");
assert_eq!(r.as_code(), Some("COWRS"));
assert_eq!(r.as_address(), None);Sourcepub fn new(address: impl Into<String>) -> Self
👎Deprecated since 1.1.0: use Referrer::address or Referrer::code explicitly
pub fn new(address: impl Into<String>) -> Self
use Referrer::address or Referrer::code explicitly
Deprecated alias for Referrer::address — kept so existing
v1.13.0-era call sites keep compiling unchanged.
New code should call Referrer::address or Referrer::code
explicitly to make the schema-version affinity obvious.
Sourcepub const fn as_address(&self) -> Option<&str>
pub const fn as_address(&self) -> Option<&str>
Return the address string if this is an Self::Address variant.
Sourcepub const fn as_code(&self) -> Option<&str>
pub const fn as_code(&self) -> Option<&str>
Return the code string if this is a Self::Code variant.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Referrer
impl<'de> Deserialize<'de> for Referrer
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Referrer
impl RefUnwindSafe for Referrer
impl Send for Referrer
impl Sync for Referrer
impl Unpin for Referrer
impl UnsafeUnpin for Referrer
impl UnwindSafe for Referrer
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.