Struct sentry_contrib_native::Dsn[][src]

pub struct Dsn { /* fields omitted */ }
This is supported on crate feature transport-custom only.

Contains the pieces that are needed to build correct headers for a request based on the given DSN.

Examples

#![cfg(feature = "transport-custom")]


struct CustomTransport {
    dsn: Dsn,
};

impl CustomTransport {
    fn new(options: &Options) -> Result<Self, ()> {
        Ok(CustomTransport {
            // we can also get the DSN here
            dsn: options.dsn().and_then(|dsn| Dsn::new(dsn).ok()).ok_or(())?,
        })
    }
}

impl Transport for CustomTransport {
    fn send(&self, envelope: RawEnvelope) {
        // we need `Dsn` to build the `Request`!
        envelope.to_request(self.dsn.clone());
        // or build your own request with the help of a URL, `HeaderMap` and body.
        let (url, headers, body): (&str, HeaderMap, &[u8]) = (self.dsn.url(), self.dsn.to_headers(), envelope.serialize().as_bytes());
    }
}

let dsn = "https://public_key_1234@organization_1234.ingest.sentry.io/project_id_1234";

let mut options = Options::new();
options.set_dsn(dsn);
// we can take the `dsn` right here
let custom_transport = CustomTransport {
    dsn: Dsn::new(dsn)?,
};
options.set_transport(move |_| Ok(custom_transport));
// this is also possible
options.set_transport(|options| Ok(CustomTransport {
    dsn: options.dsn().and_then(|dsn| Dsn::new(dsn).ok()).ok_or(())?,
}));
// or use a method more directly
options.set_transport(CustomTransport::new);

Implementations

impl Dsn[src]

pub fn new(dsn: &str) -> Result<Self, Error>[src]

Creates a new Dsn from a str.

Errors

Fails with Error::Transport if the DSN is invalid.

#[must_use]
pub fn auth(&self) -> &str
[src]

The auth header value.

#[must_use]
pub fn url(&self) -> &str
[src]

The full URL to send envelopes to.

#[must_use]
pub fn into_parts(self) -> Parts
[src]

Consume Dsn and return it’s parts.

#[must_use]
pub fn to_headers(&self) -> HeaderMap
[src]

Yields a HeaderMap to build a correct HTTP request with this Dsn.

Trait Implementations

impl Clone for Dsn[src]

impl Debug for Dsn[src]

impl Eq for Dsn[src]

impl FromStr for Dsn[src]

type Err = Error

The associated error which can be returned from parsing.

impl Hash for Dsn[src]

impl Ord for Dsn[src]

impl PartialEq<Dsn> for Dsn[src]

impl PartialOrd<Dsn> for Dsn[src]

impl StructuralEq for Dsn[src]

impl StructuralPartialEq for Dsn[src]

impl TryFrom<&'_ str> for Dsn[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for Dsn

impl Send for Dsn

impl Sync for Dsn

impl Unpin for Dsn

impl UnwindSafe for Dsn

Blanket Implementations

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

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.