webbind 0.1.44

Rust bindings for the web api, auto-generated from WebIDL
Documentation
use super::*;

/// The Blob class.
/// [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Blob {
    inner: Any,
}

impl FromVal for Blob {
    fn from_val(v: &Any) -> Self {
        Blob {
            inner: Any::from_val(v),
        }
    }
    fn take_ownership(v: AnyHandle) -> Self {
        Self::from_val(&Any::take_ownership(v))
    }
    fn as_handle(&self) -> AnyHandle {
        self.inner.as_handle()
    }
}

impl core::ops::Deref for Blob {
    type Target = Any;
    fn deref(&self) -> &Self::Target {
        &self.inner
    }
}

impl core::ops::DerefMut for Blob {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.inner
    }
}

impl AsRef<Any> for Blob {
    fn as_ref(&self) -> &Any {
        &self.inner
    }
}

impl AsMut<Any> for Blob {
    fn as_mut(&mut self) -> &mut Any {
        &mut self.inner
    }
}

impl From<Blob> for Any {
    fn from(s: Blob) -> Any {
        let handle = s.inner.as_handle();
        core::mem::forget(s);
        Any::take_ownership(handle)
    }
}

impl From<&Blob> for Any {
    fn from(s: &Blob) -> Any {
        s.inner.clone().into()
    }
}

jsbind::utils::impl_dyn_cast!(Blob);

impl Blob {
    /// Getter of the `size` attribute.
    /// [`Blob.size`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/size)
    pub fn size(&self) -> u64 {
        self.inner.get("size").as_::<u64>()
    }
}
impl Blob {
    /// Getter of the `type` attribute.
    /// [`Blob.type`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/type)
    pub fn type_(&self) -> JsString {
        self.inner.get("type").as_::<JsString>()
    }
}

impl Blob {
    /// The `new Blob(..)` constructor, creating a new Blob instance
    pub fn new() -> Blob {
        Self {
            inner: Any::global("Blob").new(&[]).as_::<Any>(),
        }
    }
}

impl Blob {
    /// The `new Blob(..)` constructor, creating a new Blob instance
    pub fn new_with_blob_parts(blob_parts: &TypedArray<Any>) -> Blob {
        Self {
            inner: Any::global("Blob").new(&[blob_parts.into()]).as_::<Any>(),
        }
    }
}

impl Blob {
    /// The `new Blob(..)` constructor, creating a new Blob instance
    pub fn new_with_blob_parts_and_options(
        blob_parts: &TypedArray<Any>,
        options: &BlobPropertyBag,
    ) -> Blob {
        Self {
            inner: Any::global("Blob")
                .new(&[blob_parts.into(), options.into()])
                .as_::<Any>(),
        }
    }
}

impl Blob {
    /// The slice method.
    /// [`Blob.slice`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice)
    pub fn slice(&self) -> Blob {
        self.inner.call("slice", &[]).as_::<Blob>()
    }
}
impl Blob {
    /// The slice method.
    /// [`Blob.slice`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice)
    pub fn slice_with_start(&self, start: i64) -> Blob {
        self.inner.call("slice", &[start.into()]).as_::<Blob>()
    }
}
impl Blob {
    /// The slice method.
    /// [`Blob.slice`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice)
    pub fn slice_with_start_and_end(&self, start: i64, end: i64) -> Blob {
        self.inner
            .call("slice", &[start.into(), end.into()])
            .as_::<Blob>()
    }
}
impl Blob {
    /// The slice method.
    /// [`Blob.slice`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice)
    pub fn slice_with_start_and_end_and_content_type(
        &self,
        start: i64,
        end: i64,
        content_type: &JsString,
    ) -> Blob {
        self.inner
            .call("slice", &[start.into(), end.into(), content_type.into()])
            .as_::<Blob>()
    }
}
impl Blob {
    /// The stream method.
    /// [`Blob.stream`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/stream)
    pub fn stream(&self) -> ReadableStream {
        self.inner.call("stream", &[]).as_::<ReadableStream>()
    }
}
impl Blob {
    /// The text method.
    /// [`Blob.text`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/text)
    pub fn text(&self) -> Promise<JsString> {
        self.inner.call("text", &[]).as_::<Promise<JsString>>()
    }
}
impl Blob {
    /// The arrayBuffer method.
    /// [`Blob.arrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer)
    pub fn array_buffer(&self) -> Promise<ArrayBuffer> {
        self.inner
            .call("arrayBuffer", &[])
            .as_::<Promise<ArrayBuffer>>()
    }
}
impl Blob {
    /// The bytes method.
    /// [`Blob.bytes`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/bytes)
    pub fn bytes(&self) -> Promise<Uint8Array> {
        self.inner.call("bytes", &[]).as_::<Promise<Uint8Array>>()
    }
}