Skip to content

Commit b577f84

Browse files
committed
s/Generator/Coroutine/
1 parent ed0df40 commit b577f84

File tree

7 files changed

+42
-42
lines changed

7 files changed

+42
-42
lines changed

alloc/src/boxed.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ use core::marker::Tuple;
159159
use core::marker::Unsize;
160160
use core::mem::{self, SizedTypeProperties};
161161
use core::ops::{
162-
CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Generator, GeneratorState, Receiver,
162+
CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut, DispatchFromDyn, Receiver,
163163
};
164164
use core::pin::Pin;
165165
use core::ptr::{self, NonNull, Unique};
@@ -2107,27 +2107,27 @@ impl<T: ?Sized, A: Allocator> AsMut<T> for Box<T, A> {
21072107
impl<T: ?Sized, A: Allocator> Unpin for Box<T, A> where A: 'static {}
21082108

21092109
#[unstable(feature = "generator_trait", issue = "43122")]
2110-
impl<G: ?Sized + Generator<R> + Unpin, R, A: Allocator> Generator<R> for Box<G, A>
2110+
impl<G: ?Sized + Coroutine<R> + Unpin, R, A: Allocator> Coroutine<R> for Box<G, A>
21112111
where
21122112
A: 'static,
21132113
{
21142114
type Yield = G::Yield;
21152115
type Return = G::Return;
21162116

2117-
fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
2117+
fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return> {
21182118
G::resume(Pin::new(&mut *self), arg)
21192119
}
21202120
}
21212121

21222122
#[unstable(feature = "generator_trait", issue = "43122")]
2123-
impl<G: ?Sized + Generator<R>, R, A: Allocator> Generator<R> for Pin<Box<G, A>>
2123+
impl<G: ?Sized + Coroutine<R>, R, A: Allocator> Coroutine<R> for Pin<Box<G, A>>
21242124
where
21252125
A: 'static,
21262126
{
21272127
type Yield = G::Yield;
21282128
type Return = G::Return;
21292129

2130-
fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
2130+
fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return> {
21312131
G::resume((*self).as_mut(), arg)
21322132
}
21332133
}

core/src/future/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub use poll_fn::{poll_fn, PollFn};
3838

3939
/// This type is needed because:
4040
///
41-
/// a) Generators cannot implement `for<'a, 'b> Generator<&'a mut Context<'b>>`, so we need to pass
41+
/// a) Coroutines cannot implement `for<'a, 'b> Coroutine<&'a mut Context<'b>>`, so we need to pass
4242
/// a raw pointer (see <https://github.com/rust-lang/rust/issues/68923>).
4343
/// b) Raw pointers and `NonNull` aren't `Send` or `Sync`, so that would make every single future
4444
/// non-Send/Sync as well, and we don't want that.

core/src/iter/sources/from_generator.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::fmt;
2-
use crate::ops::{Generator, GeneratorState};
2+
use crate::ops::{Coroutine, CoroutineState};
33
use crate::pin::Pin;
44

55
/// Creates a new iterator where each iteration calls the provided generator.
@@ -24,8 +24,8 @@ use crate::pin::Pin;
2424
/// ```
2525
#[inline]
2626
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
27-
pub fn from_generator<G: Generator<Return = ()> + Unpin>(generator: G) -> FromGenerator<G> {
28-
FromGenerator(generator)
27+
pub fn from_generator<G: Coroutine<Return = ()> + Unpin>(generator: G) -> FromCoroutine<G> {
28+
FromCoroutine(generator)
2929
}
3030

3131
/// 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
3636
/// [`iter::from_generator()`]: from_generator
3737
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
3838
#[derive(Clone)]
39-
pub struct FromGenerator<G>(G);
39+
pub struct FromCoroutine<G>(G);
4040

4141
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
42-
impl<G: Generator<Return = ()> + Unpin> Iterator for FromGenerator<G> {
42+
impl<G: Coroutine<Return = ()> + Unpin> Iterator for FromCoroutine<G> {
4343
type Item = G::Yield;
4444

4545
fn next(&mut self) -> Option<Self::Item> {
4646
match Pin::new(&mut self.0).resume(()) {
47-
GeneratorState::Yielded(n) => Some(n),
48-
GeneratorState::Complete(()) => None,
47+
CoroutineState::Yielded(n) => Some(n),
48+
CoroutineState::Complete(()) => None,
4949
}
5050
}
5151
}
5252

5353
#[unstable(feature = "iter_from_generator", issue = "43122", reason = "generators are unstable")]
54-
impl<G> fmt::Debug for FromGenerator<G> {
54+
impl<G> fmt::Debug for FromCoroutine<G> {
5555
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56-
f.debug_struct("FromGenerator").finish()
56+
f.debug_struct("FromCoroutine").finish()
5757
}
5858
}

core/src/ops/generator.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use crate::pin::Pin;
33

44
/// The result of a generator resumption.
55
///
6-
/// This enum is returned from the `Generator::resume` method and indicates the
6+
/// This enum is returned from the `Coroutine::resume` method and indicates the
77
/// possible return values of a generator. Currently this corresponds to either
88
/// a suspension point (`Yielded`) or a termination point (`Complete`).
99
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
1010
#[lang = "generator_state"]
1111
#[unstable(feature = "generator_trait", issue = "43122")]
12-
pub enum GeneratorState<Y, R> {
12+
pub enum CoroutineState<Y, R> {
1313
/// The generator suspended with a value.
1414
///
1515
/// This state indicates that a generator has been suspended, and typically
@@ -28,7 +28,7 @@ pub enum GeneratorState<Y, R> {
2828

2929
/// The trait implemented by builtin generator types.
3030
///
31-
/// Generators, also commonly referred to as coroutines, are currently an
31+
/// Coroutines, also commonly referred to as coroutines, are currently an
3232
/// experimental language feature in Rust. Added in [RFC 2033] generators are
3333
/// currently intended to primarily provide a building block for async/await
3434
/// syntax but will likely extend to also providing an ergonomic definition for
@@ -41,7 +41,7 @@ pub enum GeneratorState<Y, R> {
4141
/// ```rust
4242
/// #![feature(generators, generator_trait)]
4343
///
44-
/// use std::ops::{Generator, GeneratorState};
44+
/// use std::ops::{Coroutine, CoroutineState};
4545
/// use std::pin::Pin;
4646
///
4747
/// fn main() {
@@ -51,11 +51,11 @@ pub enum GeneratorState<Y, R> {
5151
/// };
5252
///
5353
/// match Pin::new(&mut generator).resume(()) {
54-
/// GeneratorState::Yielded(1) => {}
54+
/// CoroutineState::Yielded(1) => {}
5555
/// _ => panic!("unexpected return from resume"),
5656
/// }
5757
/// match Pin::new(&mut generator).resume(()) {
58-
/// GeneratorState::Complete("foo") => {}
58+
/// CoroutineState::Complete("foo") => {}
5959
/// _ => panic!("unexpected return from resume"),
6060
/// }
6161
/// }
@@ -68,7 +68,7 @@ pub enum GeneratorState<Y, R> {
6868
#[lang = "generator"]
6969
#[unstable(feature = "generator_trait", issue = "43122")]
7070
#[fundamental]
71-
pub trait Generator<R = ()> {
71+
pub trait Coroutine<R = ()> {
7272
/// The type of value this generator yields.
7373
///
7474
/// This associated type corresponds to the `yield` expression and the
@@ -95,10 +95,10 @@ pub trait Generator<R = ()> {
9595
///
9696
/// # Return value
9797
///
98-
/// The `GeneratorState` enum returned from this function indicates what
98+
/// The `CoroutineState` enum returned from this function indicates what
9999
/// state the generator is in upon returning. If the `Yielded` variant is
100100
/// returned then the generator has reached a suspension point and a value
101-
/// has been yielded out. Generators in this state are available for
101+
/// has been yielded out. Coroutines in this state are available for
102102
/// resumption at a later point.
103103
///
104104
/// If `Complete` is returned then the generator has completely finished
@@ -110,26 +110,26 @@ pub trait Generator<R = ()> {
110110
/// This function may panic if it is called after the `Complete` variant has
111111
/// been returned previously. While generator literals in the language are
112112
/// guaranteed to panic on resuming after `Complete`, this is not guaranteed
113-
/// for all implementations of the `Generator` trait.
114-
fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return>;
113+
/// for all implementations of the `Coroutine` trait.
114+
fn resume(self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return>;
115115
}
116116

117117
#[unstable(feature = "generator_trait", issue = "43122")]
118-
impl<G: ?Sized + Generator<R>, R> Generator<R> for Pin<&mut G> {
118+
impl<G: ?Sized + Coroutine<R>, R> Coroutine<R> for Pin<&mut G> {
119119
type Yield = G::Yield;
120120
type Return = G::Return;
121121

122-
fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
122+
fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return> {
123123
G::resume((*self).as_mut(), arg)
124124
}
125125
}
126126

127127
#[unstable(feature = "generator_trait", issue = "43122")]
128-
impl<G: ?Sized + Generator<R> + Unpin, R> Generator<R> for &mut G {
128+
impl<G: ?Sized + Coroutine<R> + Unpin, R> Coroutine<R> for &mut G {
129129
type Yield = G::Yield;
130130
type Return = G::Return;
131131

132-
fn resume(mut self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
132+
fn resume(mut self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return> {
133133
G::resume(Pin::new(&mut *self), arg)
134134
}
135135
}

core/src/ops/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub use self::try_trait::Residual;
199199
pub(crate) use self::try_trait::{ChangeOutputType, NeverShortCircuit};
200200

201201
#[unstable(feature = "generator_trait", issue = "43122")]
202-
pub use self::generator::{Generator, GeneratorState};
202+
pub use self::generator::{Coroutine, CoroutineState};
203203

204204
#[unstable(feature = "coerce_unsized", issue = "18598")]
205205
pub use self::unsize::CoerceUnsized;

core/src/pin.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,16 +1085,16 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
10851085
/// # assert_eq!(42, block_on(async { 42 }));
10861086
/// ```
10871087
///
1088-
/// ### With `Generator`s
1088+
/// ### With `Coroutine`s
10891089
///
10901090
/// ```rust
10911091
/// #![feature(generators, generator_trait)]
10921092
/// use core::{
1093-
/// ops::{Generator, GeneratorState},
1093+
/// ops::{Coroutine, CoroutineState},
10941094
/// pin::pin,
10951095
/// };
10961096
///
1097-
/// fn generator_fn() -> impl Generator<Yield = usize, Return = ()> /* not Unpin */ {
1097+
/// fn generator_fn() -> impl Coroutine<Yield = usize, Return = ()> /* not Unpin */ {
10981098
/// // Allow generator to be self-referential (not `Unpin`)
10991099
/// // vvvvvv so that locals can cross yield points.
11001100
/// static || {
@@ -1109,16 +1109,16 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
11091109
/// fn main() {
11101110
/// let mut generator = pin!(generator_fn());
11111111
/// match generator.as_mut().resume(()) {
1112-
/// GeneratorState::Yielded(0) => {},
1112+
/// CoroutineState::Yielded(0) => {},
11131113
/// _ => unreachable!(),
11141114
/// }
11151115
/// match generator.as_mut().resume(()) {
1116-
/// GeneratorState::Yielded(3) => {},
1116+
/// CoroutineState::Yielded(3) => {},
11171117
/// _ => unreachable!(),
11181118
/// }
11191119
/// match generator.resume(()) {
1120-
/// GeneratorState::Yielded(_) => unreachable!(),
1121-
/// GeneratorState::Complete(()) => {},
1120+
/// CoroutineState::Yielded(_) => unreachable!(),
1121+
/// CoroutineState::Complete(()) => {},
11221122
/// }
11231123
/// }
11241124
/// ```

core/src/sync/exclusive.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use core::fmt;
44
use core::future::Future;
55
use core::marker::Tuple;
6-
use core::ops::{Generator, GeneratorState};
6+
use core::ops::{Coroutine, CoroutineState};
77
use core::pin::Pin;
88
use core::task::{Context, Poll};
99

@@ -207,15 +207,15 @@ where
207207
}
208208

209209
#[unstable(feature = "generator_trait", issue = "43122")] // also #98407
210-
impl<R, G> Generator<R> for Exclusive<G>
210+
impl<R, G> Coroutine<R> for Exclusive<G>
211211
where
212-
G: Generator<R> + ?Sized,
212+
G: Coroutine<R> + ?Sized,
213213
{
214214
type Yield = G::Yield;
215215
type Return = G::Return;
216216

217217
#[inline]
218-
fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return> {
218+
fn resume(self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return> {
219219
G::resume(self.get_pin_mut(), arg)
220220
}
221221
}

0 commit comments

Comments
 (0)