Skip to content

Commit 2059bac

Browse files
weihanglopetrochenkov
authored andcommitted
docs: add more intra-doc links
1 parent 5530ff4 commit 2059bac

File tree

2 files changed

+54
-49
lines changed

2 files changed

+54
-49
lines changed

src/error.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ type RawFd = std::os::unix::io::RawFd;
33
#[cfg(not(unix))]
44
type RawFd = std::convert::Infallible;
55

6-
/// Error type for `from_env_ext` function.
6+
/// Error type for [`Client::from_env_ext`] function.
7+
///
8+
/// [`Client::from_env_ext`]: crate::Client::from_env_ext
79
#[derive(Debug)]
810
pub struct FromEnvError {
911
pub(crate) inner: FromEnvErrorInner,
1012
}
1113

12-
/// Kind of an error returned from `from_env_ext` function.
14+
/// Kind of an error returned from [`Client::from_env_ext`] function.
15+
///
16+
/// [`Client::from_env_ext`]: crate::Client::from_env_ext
1317
#[derive(Debug)]
1418
#[non_exhaustive]
1519
pub enum FromEnvErrorKind {

src/lib.rs

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ mod imp;
109109
/// Some usage examples can be found in the crate documentation for using a
110110
/// client.
111111
///
112-
/// Note that a `Client` implements the `Clone` trait, and all instances of a
113-
/// `Client` refer to the same jobserver instance.
112+
/// Note that a [`Client`] implements the [`Clone`] trait, and all instances of
113+
/// a [`Client`] refer to the same jobserver instance.
114114
#[derive(Clone, Debug)]
115115
pub struct Client {
116116
inner: Arc<imp::Client>,
@@ -128,13 +128,13 @@ pub struct Acquired {
128128
}
129129

130130
impl Acquired {
131-
/// This drops the `Acquired` token without releasing the associated token.
131+
/// This drops the [`Acquired`] token without releasing the associated token.
132132
///
133133
/// This is not generally useful, but can be helpful if you do not have the
134134
/// ability to store an Acquired token but need to not yet release it.
135135
///
136-
/// You'll typically want to follow this up with a call to `release_raw` or
137-
/// similar to actually release the token later on.
136+
/// You'll typically want to follow this up with a call to
137+
/// [`Client::release_raw`] or similar to actually release the token later on.
138138
pub fn drop_without_releasing(mut self) {
139139
self.disabled = true;
140140
}
@@ -156,7 +156,7 @@ struct HelperInner {
156156
use error::FromEnvErrorInner;
157157
pub use error::{FromEnvError, FromEnvErrorKind};
158158

159-
/// Return type for `from_env_ext` function.
159+
/// Return type for [`Client::from_env_ext`] function.
160160
#[derive(Debug)]
161161
pub struct FromEnv {
162162
/// Result of trying to get jobserver client from env.
@@ -186,12 +186,12 @@ impl Client {
186186
///
187187
/// A client to the jobserver created will be returned. This client will
188188
/// allow at most `limit` tokens to be acquired from it in parallel. More
189-
/// calls to `acquire` will cause the calling thread to block.
189+
/// calls to [`Client::acquire`] will cause the calling thread to block.
190190
///
191-
/// Note that the created `Client` is not automatically inherited into
191+
/// Note that the created [`Client`] is not automatically inherited into
192192
/// spawned child processes from this program. Manual usage of the
193-
/// `configure` function is required for a child process to have access to a
194-
/// job server.
193+
/// [`Client::configure`] function is required for a child process to have
194+
/// access to a job server.
195195
///
196196
/// # Examples
197197
///
@@ -219,14 +219,14 @@ impl Client {
219219
/// it's passing down. This function will attempt to look for these details
220220
/// and connect to the jobserver.
221221
///
222-
/// Note that the created `Client` is not automatically inherited into
222+
/// Note that the created [`Client`] is not automatically inherited into
223223
/// spawned child processes from this program. Manual usage of the
224-
/// `configure` function is required for a child process to have access to a
225-
/// job server.
224+
/// [`Client::configure`] function is required for a child process to have
225+
/// access to a job server.
226226
///
227227
/// # Return value
228228
///
229-
/// `FromEnv` contains result and relevant environment variable.
229+
/// [`FromEnv`] contains result and relevant environment variable.
230230
/// If a jobserver was found in the environment and it looks correct then
231231
/// result with the connected client will be returned. In other cases
232232
/// result will contain `Err(FromEnvErr)`.
@@ -281,7 +281,7 @@ impl Client {
281281
/// Attempts to connect to the jobserver specified in this process's
282282
/// environment.
283283
///
284-
/// Wraps `from_env_ext` and discards error details.
284+
/// Wraps [`Client::from_env_ext`] and discards error details.
285285
///
286286
/// # Safety
287287
///
@@ -306,7 +306,7 @@ impl Client {
306306
///
307307
/// # Return value
308308
///
309-
/// On successful acquisition of a token an instance of `Acquired` is
309+
/// On successful acquisition of a token an instance of [`Acquired`] is
310310
/// returned. This structure, when dropped, will release the token back to
311311
/// the jobserver. It's recommended to avoid leaking this value.
312312
///
@@ -342,9 +342,10 @@ impl Client {
342342
///
343343
/// This function is required to be called to ensure that a jobserver is
344344
/// properly inherited to a child process. If this function is *not* called
345-
/// then this `Client` will not be accessible in the child process. In other
346-
/// words, if not called, then `Client::from_env` will return `None` in the
347-
/// child process (or the equivalent of `Child::from_env` that `make` uses).
345+
/// then this [`Client`] will not be accessible in the child process. In
346+
/// other words, if not called, then [`Client::from_env`] will return `None`
347+
/// in the child process (or the equivalent of [`Client::from_env`] that
348+
/// `make` uses).
348349
///
349350
/// ## Platform-specific behavior
350351
///
@@ -363,9 +364,10 @@ impl Client {
363364
///
364365
/// This function is required to be called to ensure that a jobserver is
365366
/// properly inherited to a child process. If this function is *not* called
366-
/// then this `Client` will not be accessible in the child process. In other
367-
/// words, if not called, then `Client::from_env` will return `None` in the
368-
/// child process (or the equivalent of `Child::from_env` that `make` uses).
367+
/// then this [`Client`] will not be accessible in the child process. In
368+
/// other words, if not called, then [`Client::from_env`] will return `None`
369+
/// in the child process (or the equivalent of [`Client::from_env`] that
370+
/// `make` uses).
369371
///
370372
/// ## Platform-specific behavior
371373
///
@@ -391,19 +393,18 @@ impl Client {
391393
format!("-j --jobserver-fds={0} --jobserver-auth={0}", arg)
392394
}
393395

394-
/// Converts this `Client` into a helper thread to deal with a blocking
395-
/// `acquire` function a little more easily.
396+
/// Converts this [`Client`] into a helper thread to deal with a blocking
397+
/// [`Client::acquire`] function a little more easily.
396398
///
397-
/// The fact that the `acquire` function on `Client` blocks isn't always
398-
/// the easiest to work with. Typically you're using a jobserver to
399-
/// manage running other events in parallel! This means that you need to
400-
/// either (a) wait for an existing job to finish or (b) wait for a
401-
/// new token to become available.
399+
/// The fact that the [`Client::acquire`] isn't always the easiest to work
400+
/// with. Typically you're using a jobserver to manage running other events
401+
/// in parallel! This means that you need to either (a) wait for an existing
402+
/// job to finish or (b) wait for a new token to become available.
402403
///
403-
/// Unfortunately the blocking in `acquire` happens at the implementation
404-
/// layer of jobservers. On Unix this requires a blocking call to `read`
405-
/// and on Windows this requires one of the `WaitFor*` functions. Both
406-
/// of these situations aren't the easiest to deal with:
404+
/// Unfortunately the blocking in [`Client::acquire`] happens at the
405+
/// implementation layer of jobservers. On Unix this requires a blocking
406+
/// call to `read` and on Windows this requires one of the `WaitFor*`
407+
/// functions. Both of these situations aren't the easiest to deal with:
407408
///
408409
/// * On Unix there's basically only one way to wake up a `read` early, and
409410
/// that's through a signal. This is what the `make` implementation
@@ -419,7 +420,7 @@ impl Client {
419420
/// unfortunately.
420421
///
421422
/// This function essentially attempts to ease these limitations by
422-
/// converting this `Client` into a helper thread spawned into this
423+
/// converting this [`Client`] into a helper thread spawned into this
423424
/// process. The application can then request that the helper thread
424425
/// acquires tokens and the provided closure will be invoked for each token
425426
/// acquired.
@@ -429,23 +430,23 @@ impl Client {
429430
///
430431
/// # Arguments
431432
///
432-
/// This function will consume the `Client` provided to be transferred to
433+
/// This function will consume the [`Client`] provided to be transferred to
433434
/// the helper thread that is spawned. Additionally a closure `f` is
434435
/// provided to be invoked whenever a token is acquired.
435436
///
436437
/// This closure is only invoked after calls to
437-
/// `HelperThread::request_token` have been made and a token itself has
438+
/// [`HelperThread::request_token`] have been made and a token itself has
438439
/// been acquired. If an error happens while acquiring the token then
439440
/// an error will be yielded to the closure as well.
440441
///
441442
/// # Return Value
442443
///
443-
/// This function will return an instance of the `HelperThread` structure
444+
/// This function will return an instance of the [`HelperThread`] structure
444445
/// which is used to manage the helper thread associated with this client.
445-
/// Through the `HelperThread` you'll request that tokens are acquired.
446+
/// Through the [`HelperThread`] you'll request that tokens are acquired.
446447
/// When acquired, the closure provided here is invoked.
447448
///
448-
/// When the `HelperThread` structure is returned it will be gracefully
449+
/// When the [`HelperThread`] structure is returned it will be gracefully
449450
/// torn down, and the calling thread will be blocked until the thread is
450451
/// torn down (which should be prompt).
451452
///
@@ -482,19 +483,19 @@ impl Client {
482483

483484
/// Blocks the current thread until a token is acquired.
484485
///
485-
/// This is the same as `acquire`, except that it doesn't return an RAII
486-
/// helper. If successful the process will need to guarantee that
487-
/// `release_raw` is called in the future.
486+
/// This is the same as [`Client::acquire`], except that it doesn't return
487+
/// an RAII helper. If successful the process will need to guarantee that
488+
/// [`Client::release_raw`] is called in the future.
488489
pub fn acquire_raw(&self) -> io::Result<()> {
489490
self.inner.acquire()?;
490491
Ok(())
491492
}
492493

493494
/// Releases a jobserver token back to the original jobserver.
494495
///
495-
/// This is intended to be paired with `acquire_raw` if it was called, but
496-
/// in some situations it could also be called to relinquish a process's
497-
/// implicit token temporarily which is then re-acquired later.
496+
/// This is intended to be paired with [`Client::acquire_raw`] if it was
497+
/// called, but in some situations it could also be called to relinquish a
498+
/// process's implicit token temporarily which is then re-acquired later.
498499
pub fn release_raw(&self) -> io::Result<()> {
499500
self.inner.release(None)?;
500501
Ok(())
@@ -509,7 +510,7 @@ impl Drop for Acquired {
509510
}
510511
}
511512

512-
/// Structure returned from `Client::into_helper_thread` to manage the lifetime
513+
/// Structure returned from [`Client::into_helper_thread`] to manage the lifetime
513514
/// of the helper thread returned, see those associated docs for more info.
514515
#[derive(Debug)]
515516
pub struct HelperThread {
@@ -521,7 +522,7 @@ impl HelperThread {
521522
/// Request that the helper thread acquires a token, eventually calling the
522523
/// original closure with a token when it's available.
523524
///
524-
/// For more information, see the docs on that function.
525+
/// For more information, see the docs on [`Client::into_helper_thread`].
525526
pub fn request_token(&self) {
526527
// Indicate that there's one more request for a token and then wake up
527528
// the helper thread if it's sleeping.

0 commit comments

Comments
 (0)