diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-10-19 16:06:43 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-10-20 21:10:38 +0000 |
| commit | 60956837cfbf22bd8edd80f57a856e141f7deb8c (patch) | |
| tree | 4cc50671566d7fb411d8e933348d6785d6bc55cc /library | |
| parent | 96027d945b9d8cae622a2fa4e70d8040be2964f3 (diff) | |
| download | rust-60956837cfbf22bd8edd80f57a856e141f7deb8c.tar.gz rust-60956837cfbf22bd8edd80f57a856e141f7deb8c.zip | |
s/Generator/Coroutine/
Diffstat (limited to 'library')
| -rw-r--r-- | library/alloc/src/boxed.rs | 10 | ||||
| -rw-r--r-- | library/core/src/future/mod.rs | 2 | ||||
| -rw-r--r-- | library/core/src/iter/sources/from_generator.rs | 18 | ||||
| -rw-r--r-- | library/core/src/ops/generator.rs | 30 | ||||
| -rw-r--r-- | library/core/src/ops/mod.rs | 2 | ||||
| -rw-r--r-- | library/core/src/pin.rs | 14 | ||||
| -rw-r--r-- | library/core/src/sync/exclusive.rs | 8 |
7 files changed, 42 insertions, 42 deletions
diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 96b93830f96..d14a6188085 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -159,7 +159,7 @@ use core::marker::Tuple; use core::marker::Unsize; use core::mem::{self, SizedTypeProperties}; use core::ops::{ - CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Generator, GeneratorState, Receiver, + CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut, DispatchFromDyn, Receiver, }; use core::pin::Pin; use core::ptr::{self, NonNull, Unique}; @@ -2107,27 +2107,27 @@ impl<T: ?Sized, A: Allocator> AsMut<T> for Box<T, A> { impl<T: ?Sized, A: Allocator> Unpin for Box<T, A> where A: 'static {} #[unstable(feature = "generator_trait", issue = "43122")] -impl<G: ?Sized + Generator<R> + Unpin, R, A: Allocator> Generator<R> for Box<G, A> +impl<G: ?Sized + Coroutine<R> + Unpin, R, A: Allocator> Coroutine<R> for Box<G, A> where A: 'static, { type Yield = G::Yield; type Return = G::Return; - fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> { + fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return> { G::resume(Pin::new(&mut *self), arg) } } #[unstable(feature = "generator_trait", issue = "43122")] -impl<G: ?Sized + Generator<R>, R, A: Allocator> Generator<R> for Pin<Box<G, A>> +impl<G: ?Sized + Coroutine<R>, R, A: Allocator> Coroutine<R> for Pin<Box<G, A>> where A: 'static, { type Yield = G::Yield; type Return = G::Return; - fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> { + fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return> { G::resume((*self).as_mut(), arg) } } diff --git a/library/core/src/future/mod.rs b/library/core/src/future/mod.rs index 089493d3766..0f77a2d8343 100644 --- a/library/core/src/future/mod.rs +++ b/library/core/src/future/mod.rs @@ -38,7 +38,7 @@ pub use poll_fn::{poll_fn, PollFn}; /// This type is needed because: /// -/// a) Generators cannot implement `for<'a, 'b> Generator<&'a mut Context<'b>>`, so we need to pass +/// a) Coroutines cannot implement `for<'a, 'b> Coroutine<&'a mut Context<'b>>`, so we need to pass /// a raw pointer (see <https://github.com/rust-lang/rust/issues/68923>). /// b) Raw pointers and `NonNull` aren't `Send` or `Sync`, so that would make every single future /// non-Send/Sync as well, and we don't want that. diff --git a/library/core/src/iter/sources/from_generator.rs b/library/core/src/iter/sources/from_generator.rs index 4cbe731b222..b512f4f162c 100644 --- a/library/core/src/iter/sources/from_generator.rs +++ b/library/core/src/iter/sources/from_generator.rs @@ -1,5 +1,5 @@ use crate::fmt; -use crate::ops::{Generator, GeneratorState}; +use crate::ops::{Coroutine, CoroutineState}; use crate::pin::Pin; /// Creates a new iterator where each iteration calls the provided generator. @@ -24,8 +24,8 @@ use crate::pin::Pin; /// ``` #[inline] #[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")] -pub fn from_generator<G: Generator<Return = ()> + Unpin>(generator: G) -> FromGenerator<G> { - FromGenerator(generator) +pub fn from_generator<G: Coroutine<Return = ()> + Unpin>(generator: G) -> FromCoroutine<G> { + FromCoroutine(generator) } /// An iterator over the values yielded by an underlying generator. @@ -36,23 +36,23 @@ pub fn from_generator<G: Generator<Return = ()> + Unpin>(generator: G) -> FromGe /// [`iter::from_generator()`]: from_generator #[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")] #[derive(Clone)] -pub struct FromGenerator<G>(G); +pub struct FromCoroutine<G>(G); #[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")] -impl<G: Generator<Return = ()> + Unpin> Iterator for FromGenerator<G> { +impl<G: Coroutine<Return = ()> + Unpin> Iterator for FromCoroutine<G> { type Item = G::Yield; fn next(&mut self) -> Option<Self::Item> { match Pin::new(&mut self.0).resume(()) { - GeneratorState::Yielded(n) => Some(n), - GeneratorState::Complete(()) => None, + CoroutineState::Yielded(n) => Some(n), + CoroutineState::Complete(()) => None, } } } #[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")] -impl<G> fmt::Debug for FromGenerator<G> { +impl<G> fmt::Debug for FromCoroutine<G> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("FromGenerator").finish() + f.debug_struct("FromCoroutine").finish() } } diff --git a/library/core/src/ops/generator.rs b/library/core/src/ops/generator.rs index fee4beb1e84..f1fe55760ad 100644 --- a/library/core/src/ops/generator.rs +++ b/library/core/src/ops/generator.rs @@ -3,13 +3,13 @@ use crate::pin::Pin; /// The result of a generator resumption. /// -/// This enum is returned from the `Generator::resume` method and indicates the +/// This enum is returned from the `Coroutine::resume` method and indicates the /// possible return values of a generator. Currently this corresponds to either /// a suspension point (`Yielded`) or a termination point (`Complete`). #[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] #[lang = "generator_state"] #[unstable(feature = "generator_trait", issue = "43122")] -pub enum GeneratorState<Y, R> { +pub enum CoroutineState<Y, R> { /// The generator suspended with a value. /// /// This state indicates that a generator has been suspended, and typically @@ -28,7 +28,7 @@ pub enum GeneratorState<Y, R> { /// The trait implemented by builtin generator types. /// -/// Generators, also commonly referred to as coroutines, are currently an +/// Coroutines, also commonly referred to as coroutines, are currently an /// experimental language feature in Rust. Added in [RFC 2033] generators are /// currently intended to primarily provide a building block for async/await /// syntax but will likely extend to also providing an ergonomic definition for @@ -41,7 +41,7 @@ pub enum GeneratorState<Y, R> { /// ```rust /// #![feature(generators, generator_trait)] /// -/// use std::ops::{Generator, GeneratorState}; +/// use std::ops::{Coroutine, CoroutineState}; /// use std::pin::Pin; /// /// fn main() { @@ -51,11 +51,11 @@ pub enum GeneratorState<Y, R> { /// }; /// /// match Pin::new(&mut generator).resume(()) { -/// GeneratorState::Yielded(1) => {} +/// CoroutineState::Yielded(1) => {} /// _ => panic!("unexpected return from resume"), /// } /// match Pin::new(&mut generator).resume(()) { -/// GeneratorState::Complete("foo") => {} +/// CoroutineState::Complete("foo") => {} /// _ => panic!("unexpected return from resume"), /// } /// } @@ -68,7 +68,7 @@ pub enum GeneratorState<Y, R> { #[lang = "generator"] #[unstable(feature = "generator_trait", issue = "43122")] #[fundamental] -pub trait Generator<R = ()> { +pub trait Coroutine<R = ()> { /// The type of value this generator yields. /// /// This associated type corresponds to the `yield` expression and the @@ -95,10 +95,10 @@ pub trait Generator<R = ()> { /// /// # Return value /// - /// The `GeneratorState` enum returned from this function indicates what + /// The `CoroutineState` enum returned from this function indicates what /// state the generator is in upon returning. If the `Yielded` variant is /// returned then the generator has reached a suspension point and a value - /// has been yielded out. Generators in this state are available for + /// has been yielded out. Coroutines in this state are available for /// resumption at a later point. /// /// If `Complete` is returned then the generator has completely finished @@ -110,26 +110,26 @@ pub trait Generator<R = ()> { /// This function may panic if it is called after the `Complete` variant has /// been returned previously. While generator literals in the language are /// guaranteed to panic on resuming after `Complete`, this is not guaranteed - /// for all implementations of the `Generator` trait. - fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return>; + /// for all implementations of the `Coroutine` trait. + fn resume(self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return>; } #[unstable(feature = "generator_trait", issue = "43122")] -impl<G: ?Sized + Generator<R>, R> Generator<R> for Pin<&mut G> { +impl<G: ?Sized + Coroutine<R>, R> Coroutine<R> for Pin<&mut G> { type Yield = G::Yield; type Return = G::Return; - fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> { + fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return> { G::resume((*self).as_mut(), arg) } } #[unstable(feature = "generator_trait", issue = "43122")] -impl<G: ?Sized + Generator<R> + Unpin, R> Generator<R> for &mut G { +impl<G: ?Sized + Coroutine<R> + Unpin, R> Coroutine<R> for &mut G { type Yield = G::Yield; type Return = G::Return; - fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> { + fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return> { G::resume(Pin::new(&mut *self), arg) } } diff --git a/library/core/src/ops/mod.rs b/library/core/src/ops/mod.rs index 97d9b750d92..eb972e9f6c5 100644 --- a/library/core/src/ops/mod.rs +++ b/library/core/src/ops/mod.rs @@ -199,7 +199,7 @@ pub use self::try_trait::Residual; pub(crate) use self::try_trait::{ChangeOutputType, NeverShortCircuit}; #[unstable(feature = "generator_trait", issue = "43122")] -pub use self::generator::{Generator, GeneratorState}; +pub use self::generator::{Coroutine, CoroutineState}; #[unstable(feature = "coerce_unsized", issue = "18598")] pub use self::unsize::CoerceUnsized; diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs index 94c682b615a..14344e3890b 100644 --- a/library/core/src/pin.rs +++ b/library/core/src/pin.rs @@ -1085,16 +1085,16 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {} /// # assert_eq!(42, block_on(async { 42 })); /// ``` /// -/// ### With `Generator`s +/// ### With `Coroutine`s /// /// ```rust /// #![feature(generators, generator_trait)] /// use core::{ -/// ops::{Generator, GeneratorState}, +/// ops::{Coroutine, CoroutineState}, /// pin::pin, /// }; /// -/// fn generator_fn() -> impl Generator<Yield = usize, Return = ()> /* not Unpin */ { +/// fn generator_fn() -> impl Coroutine<Yield = usize, Return = ()> /* not Unpin */ { /// // Allow generator to be self-referential (not `Unpin`) /// // vvvvvv so that locals can cross yield points. /// static || { @@ -1109,16 +1109,16 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {} /// fn main() { /// let mut generator = pin!(generator_fn()); /// match generator.as_mut().resume(()) { -/// GeneratorState::Yielded(0) => {}, +/// CoroutineState::Yielded(0) => {}, /// _ => unreachable!(), /// } /// match generator.as_mut().resume(()) { -/// GeneratorState::Yielded(3) => {}, +/// CoroutineState::Yielded(3) => {}, /// _ => unreachable!(), /// } /// match generator.resume(()) { -/// GeneratorState::Yielded(_) => unreachable!(), -/// GeneratorState::Complete(()) => {}, +/// CoroutineState::Yielded(_) => unreachable!(), +/// CoroutineState::Complete(()) => {}, /// } /// } /// ``` diff --git a/library/core/src/sync/exclusive.rs b/library/core/src/sync/exclusive.rs index ff538d55c60..5aa45610197 100644 --- a/library/core/src/sync/exclusive.rs +++ b/library/core/src/sync/exclusive.rs @@ -3,7 +3,7 @@ use core::fmt; use core::future::Future; use core::marker::Tuple; -use core::ops::{Generator, GeneratorState}; +use core::ops::{Coroutine, CoroutineState}; use core::pin::Pin; use core::task::{Context, Poll}; @@ -207,15 +207,15 @@ where } #[unstable(feature = "generator_trait", issue = "43122")] // also #98407 -impl<R, G> Generator<R> for Exclusive<G> +impl<R, G> Coroutine<R> for Exclusive<G> where - G: Generator<R> + ?Sized, + G: Coroutine<R> + ?Sized, { type Yield = G::Yield; type Return = G::Return; #[inline] - fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> { + fn resume(self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return> { G::resume(self.get_pin_mut(), arg) } } |
