Struct ApiKey

Source
pub struct ApiKey(/* private fields */);

Implementations§

Source§

impl ApiKey

Source

pub fn new(key: impl Into<String>) -> Self

Examples found in repository?
examples/playlist.rs (line 12)
9fn main() -> Result<(), Error> {
10	futures::executor::block_on(async {
11		// take api key from enviroment variable
12		let key = ApiKey::new(&env::var("YT_API_KEY").expect("YT_API_KEY env-var not found"));
13
14		// create the PlaylistItems struct for some playlist ID
15		let result = PlaylistItems::new(key)
16			.playlist_id("PLVvjrrRCBy2JSHf9tGxGKJ-bYAN_uDCUL")
17			.max_results(50)
18			.await?;
19
20		for item in result.items {
21			println!(
22				"https://youtube.com/watch?v={}",
23				item.snippet.resource_id.video_id
24			);
25		}
26
27		Ok(())
28	})
29}
More examples
Hide additional examples
examples/complex_search.rs (line 12)
9fn main() -> Result<(), Error> {
10	futures::executor::block_on(async {
11		// take api key from enviroment variable
12		let key = ApiKey::new(&env::var("YT_API_KEY").expect("YT_API_KEY env-var not found"));
13
14		// create the SearchList struct for the query "rust lang"
15		let result = SearchList::new(key)
16			.q("rust lang")
17			.max_results(1)
18			.item_type(ItemType::Video)
19			.location(VideoLocation::new(40.73061, -73.93524))
20			.location_radius("100km")
21			.video_embeddable()
22			.await?;
23
24		// outputs the video_id of the first search result
25		println!(
26			"Title: \"{}\"",
27			result.items[0].snippet.title.as_ref().unwrap()
28		);
29		println!(
30			"https://youtube.com/watch?v={}",
31			result.items[0].id.video_id.as_ref().unwrap()
32		);
33
34		Ok(())
35	})
36}
examples/search.rs (line 12)
9fn main() -> Result<(), Error> {
10	futures::executor::block_on(async {
11		// take api key from enviroment variable
12		let key = ApiKey::new(&env::var("YT_API_KEY").expect("YT_API_KEY env-var not found"));
13
14		// create the SearchList struct for the query "rust lang"
15		let result = SearchList::new(key)
16			.q("rust lang")
17			.item_type(ItemType::Video)
18			.await?;
19
20		// outputs the title of the first search result
21		println!(
22			"Title: \"{}\"",
23			result.items[0].snippet.title.as_ref().unwrap()
24		);
25		// outputs the video id of the first search result
26		println!(
27			"https://youtube.com/watch?v={}",
28			result.items[0].id.video_id.as_ref().unwrap()
29		);
30
31		println!(
32			"Default thumbnail: {}",
33			result.items[0]
34				.snippet
35				.thumbnails
36				.as_ref()
37				.unwrap()
38				.default
39				.as_ref()
40				.unwrap()
41				.url
42		);
43
44		Ok(())
45	})
46}

Trait Implementations§

Source§

impl Clone for ApiKey

Source§

fn clone(&self) -> ApiKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ApiKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for ApiKey

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for ApiKey

§

impl RefUnwindSafe for ApiKey

§

impl Send for ApiKey

§

impl Sync for ApiKey

§

impl Unpin for ApiKey

§

impl UnwindSafe for ApiKey

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,