struct Slice(T)

Overview

A Slice is a Pointer with an associated size.

While a pointer is unsafe because no bound checks are performed when reading from and writing to it, reading from and writing to a slice involve bound checks. In this way, a slice is a safe alternative to Pointer.

A Slice can be created as read-only: trying to write to it will raise. For example the slice of bytes returned by String#to_slice is read-only.

Included Modules

Defined in:

chem/core_ext/slice.cr

Instance Method Summary

Instance methods inherited from module Indexable(T)

index!(of object, offset : Int = 0) : Int
index!(offset : Int = 0, &block : T -> Bool) : Int
index!

Instance Method Detail

def concat(other : self, count : Int) : self #

[View source]
def concat(other : Pointer(T), count : Int) : self #

[View source]
def concat(other : self) : self #

[View source]
def skip(& : T -> Bool) : self #

[View source]
def take_while(& : T -> Bool) : self #
Description copied from module Enumerable(T)

Passes elements to the block until the block returns a falsey value, then stops iterating and returns an Array of all prior elements.

[1, 2, 3, 4, 5, 0].take_while { |i| i < 3 } # => [1, 2]

[View source]
def unsafe_index(byte : Int) : Int32 | Nil #

[View source]
def unsafe_index(*bytes : Int) : Int32 | Nil #

[View source]