Skip to content

Commit 0de6929

Browse files
committed
improve docs for Add/Sub ops for VirtAddr
Document when the functions panic and mention Step as an alternative for those looking for a successor/predecessor operation.
1 parent 35643d2 commit 0de6929

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/addr.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,18 @@ impl fmt::Pointer for VirtAddr {
364364

365365
impl Add<u64> for VirtAddr {
366366
type Output = Self;
367+
368+
#[cfg_attr(not(feature = "step_trait"), allow(rustdoc::broken_intra_doc_links))]
369+
/// Add an offset to a virtual address.
370+
///
371+
/// This function performs normal arithmetic addition and doesn't jump the
372+
/// address gap. If you're looking for a successor operation that jumps the
373+
/// address gap, use [`Step::forward`].
374+
///
375+
/// # Panics
376+
///
377+
/// This function will panic on overflow or if the result is not a
378+
/// canonical address.
367379
#[inline]
368380
fn add(self, rhs: u64) -> Self::Output {
369381
VirtAddr::try_new(
@@ -376,6 +388,17 @@ impl Add<u64> for VirtAddr {
376388
}
377389

378390
impl AddAssign<u64> for VirtAddr {
391+
#[cfg_attr(not(feature = "step_trait"), allow(rustdoc::broken_intra_doc_links))]
392+
/// Add an offset to a virtual address.
393+
///
394+
/// This function performs normal arithmetic addition and doesn't jump the
395+
/// address gap. If you're looking for a successor operation that jumps the
396+
/// address gap, use [`Step::forward`].
397+
///
398+
/// # Panics
399+
///
400+
/// This function will panic on overflow or if the result is not a
401+
/// canonical address.
379402
#[inline]
380403
fn add_assign(&mut self, rhs: u64) {
381404
*self = *self + rhs;
@@ -384,6 +407,18 @@ impl AddAssign<u64> for VirtAddr {
384407

385408
impl Sub<u64> for VirtAddr {
386409
type Output = Self;
410+
411+
#[cfg_attr(not(feature = "step_trait"), allow(rustdoc::broken_intra_doc_links))]
412+
/// Subtract an offset from a virtual address.
413+
///
414+
/// This function performs normal arithmetic subtraction and doesn't jump
415+
/// the address gap. If you're looking for a predecessor operation that
416+
/// jumps the address gap, use [`Step::backward`].
417+
///
418+
/// # Panics
419+
///
420+
/// This function will panic on overflow or if the result is not a
421+
/// canonical address.
387422
#[inline]
388423
fn sub(self, rhs: u64) -> Self::Output {
389424
VirtAddr::try_new(
@@ -396,6 +431,17 @@ impl Sub<u64> for VirtAddr {
396431
}
397432

398433
impl SubAssign<u64> for VirtAddr {
434+
#[cfg_attr(not(feature = "step_trait"), allow(rustdoc::broken_intra_doc_links))]
435+
/// Subtract an offset from a virtual address.
436+
///
437+
/// This function performs normal arithmetic subtraction and doesn't jump
438+
/// the address gap. If you're looking for a predecessor operation that
439+
/// jumps the address gap, use [`Step::backward`].
440+
///
441+
/// # Panics
442+
///
443+
/// This function will panic on overflow or if the result is not a
444+
/// canonical address.
399445
#[inline]
400446
fn sub_assign(&mut self, rhs: u64) {
401447
*self = *self - rhs;
@@ -404,6 +450,12 @@ impl SubAssign<u64> for VirtAddr {
404450

405451
impl Sub<VirtAddr> for VirtAddr {
406452
type Output = u64;
453+
454+
/// Returns the difference between two addresses.
455+
///
456+
/// # Panics
457+
///
458+
/// This function will panic on overflow.
407459
#[inline]
408460
fn sub(self, rhs: VirtAddr) -> Self::Output {
409461
self.as_u64()

0 commit comments

Comments
 (0)