Function in bytes coil-stdlib

rfind

fn rfind(Vec<byte> hay, Vec<byte> needle) -> int
Import
use bytes::{rfind};
Source: src/bytes.hy

Returns the offset of the last needle in hay, or -1. An empty needle matches at hay.len().

Parameters#

NameType
hayVec<byte>
needleVec<byte>

Returns#

int

Contracts#

Checked according to --contracts (see Contracts).

ensures result >= -1 && result <= hay.len()
ensures result < 0 || (result + needle.len() <= hay.len() && region_eq(hay, result, needle, 0, needle.len()))

Examples#

use bytes::{rfind};
use tests::assert;
assert!(rfind("a,b,c", ",") == 3);

See also#

  • region_eq: True when a[ao..ao+n) equals b[bo..bo+n) (caller guarantees bounds).
  • to_hex: Encodes buf as lowercase hexadecimal, two digits per byte.
  • from_hex: Decodes hexadecimal text (either case) into bytes.
  • slice: Returns a copy of src[start..end] (end exclusive), with both offsets clamped to the buffer.
  • concat: Returns a new buffer holding a followed by b.
  • eq: Returns true when a and b have the same length and the same bytes.
  • find_from: Returns the offset of the first needle in hay at or after start, or -1.
  • find: Returns the offset of the first needle in hay, or -1.
↑ ↓ navigate ↵ open