Solod provides a growing set of high-level packages similar to Go's stdlib, and a low-level package to help with C interop. For full API details, see the package documentation.
bytes • c • cmp • crypto/crand • encoding/binary • errors • fmt • io • log/slog • maps • math • math/bits • math/rand • mem • os • runtime • slices • strconv • strings • time • unicode • unicode/utf8
Byte slice operations. Offers an API similar to Go's bytes package, but with fewer features.
Functions:
Clonereturns a copy of a slice.CompareandEqualcompare two slices lexicographically.Containsreports whether a subslice is within a slice.Countcounts the number of non-overlapping instances of a subslice in a slice.Cutslices around the first instance of a separator.HasPrefixandHasSuffixreport whether a slice begins/ends with a prefix/suffix.IndexandIndexBytesearch for a subslice or byte within a slice.Joinconcatenates slices with a separator.Replacereplaces occurrences of a subslice within a slice.Runesconverts a byte slice to a rune slice.SplitandSplitNsplit a slice into subslices.Stringcreates a string from a byte slice.ToLowerandToUpperreturn a copy with all letters lowercased/uppercased.TrimLeft,TrimRightandTrimSpacetrim characters from a slice.TrimPrefixandTrimSuffixtrim a prefix/suffix from a slice.
Types:
Bufferis a variable-sized buffer of bytes withReadandWritemethods.Readerreads data from a byte slice.
Low-level C interop helpers for pointers, strings, and type information.
AlignofandSizeofreturn the alignment and size of type T.Allocaallocates an array on the stack.Assertaborts with a message if a condition is false.Bytes,SliceandStringwrap C pointers to So types.CharPtr- cast a*bytetochar*.PtrAdd,PtrAsandPtrAtmanipulate pointers.Zeroreturns the zero value of type T.
Comparing ordered values. Based on Go's cmp package.
Functions:
Comparereturns -1, 0, or +1 for two ordered values.Equalreports whether two comparable values are equal.Lessreports whether x is less than y.
Types:
Funcis a comparison functionfunc(a, b any) int.FuncForreturns the appropriate comparison function for type T.
Cryptographically secure random number generation.
Readfills a slice with cryptographically secure random bytes.Readeris a global instance of a cryptographically secure RNG.Textreturns a cryptographically random string using the base32 alphabet.
Translation between numbers and byte sequences. Based on Go's encoding/binary package.
Types:
ByteOrderspecifies how to convert byte slices into unsigned integers.AppendByteOrderspecifies how to append unsigned integers into a byte slice.LittleEndianandBigEndianimplementByteOrderandAppendByteOrder.
Error creation from text messages.
New(text string) error- create a new error with the given message.
So only supports sentinel errors, which are defined at the package level using New.
Formatted I/O with functions analogous to C's printf and scanf. Uses C format verbs (not Go verbs).
PrintandPrintlnwrite strings to standard output.Printfformats and writes to standard output.Sprintfformats and writes to a string.Fprintfformats and writes to anio.Writer.Scanfscans formatted text from standard input.Sscanfscans formatted text from a string.Fscanfscans formatted text from anio.Reader.
Since Print and Println only take string arguments, you'll usually want to use the built-in functions print and println instead.
Basic interfaces to I/O primitives. Offers an API similar to Go's io package, but with fewer features.
Functions:
CopyandCopyNcopy data from a reader to a writer.ReadAllandReadFullread data from a reader.
Types:
Reader,Writer, andCloserare basic concepts for anything that does I/O.LimitedReaderandSectionReaderimplement specialized readerss.Discardis a no-op writer.
Simplified structured logging, inspired by Go's log/slog package. Provides leveled, key-value logging with zero-allocation formatting.
Functions:
Newcreates a Logger from a Handler.SetDefaultandDefaultmanage the default logger.Debug,Info,Warn,Errorlog at the corresponding level using the default logger.String,Int,Float64,Bool,TimeandDurationcreate key-value attributes.
Types:
Loggerlogs messages through aHandler.TextHandlerformats log records astimestamp LEVEL message key=value ...lines.Recordholds a log event (time, level, message, attributes).Attris a key-value pair.Valueis a tagged union holding the value.Levelrepresents severity.
Generic hashmap similar to Go's built-in map[K]V, backed by a Robin Hood hash table with automatic grow.
Functions:
Newcreates a newMapwith a given allocator.
Types:
Mapis a generic hashmap withGet,Set, andDeletemethods.Iteris an iterator over a map's key-value pairs.
Mathematical functions and constants. Offers the same API as Go's math package.
Bit counting and manipulation functions. Offers the same API as Go's math/bits package.
Pseudo-random number generation. Based on Go's math/rand/v2 package.
Top-level functions use a global Rand with a PCG source seeded by runtime.Seed.
Functions:
Int,Int32,Int64return non-negative pseudo-random integers.Uint,Uint32,Uint64return pseudo-random unsigned integers.IntN,Int32N,Int64Nreturn non-negative pseudo-random integers in [0,n).UintN,Uint32N,Uint64Nreturn pseudo-random unsigned integers in [0,n).Float32andFloat64return pseudo-random floats in [0.0,1.0).
Types:
Sourceis an interface for a source of pseudo-randomuint64values.PCGis a PCG generator with 128 bits of internal state. ImplementsSource.Randwraps aSourceand provides the same methods as the top-level functions.
Memory allocation with a pluggable allocator interface.
Functions:
Alloc/Free- allocate/free a single value.AllocSlice/FreeSlice- allocate/free a slice.
Types:
Allocatorinterface - custom allocator support (Alloc,Realloc,Free).SystemAllocator- default allocator backed by Ccalloc/realloc/free.Arena- bump allocator backed by a fixed buffer (Alloc,Realloc,Reset).
File I/O and filesystem operations. Offers an API similar to Go's os package, built on POSIX APIs.
Functions:
Create,Open,OpenFileopen files for reading and/or writing.ReadFileandWriteFileread or write an entire file.ReadDirreads a directory and returns its entries.StatandLstatreturn file information.Chmod,Chown,Lchown,Chtimeschange file attributes.Renamerenames (moves) a file.Removeremoves a file or empty directory.Mkdircreates a directory.TempDir,CreateTemp,MkdirTempwork with temporary files and directories.GetwdandChdirmanage the current working directory.Getenv,LookupEnv,SetenvandUnsetenvmanage environment variables.Getpid,Getppid,Getuid,Geteuid,Getgid,Getegidreturn process/user info.Exitterminates the program with the given status code.
Types:
Filerepresents an open file with methods for reading and writing data.FileInfodescribes a file (returned byStatandLstat).FileModerepresents a file's mode and permission bits.DirEntrydescribes an entry in a directory (returned byReadDir).
Information about the environment where the program was compiled, and runtime utilities.
GOOSandGOARCHspecify the target operating system and architecture.Versionreturns So's compiler version (git commit hash or tag).Seedreturns a cryptographically secure random 64-bit seed.
Operations on slices:
MakeandMakeCapallocate a slice,Freedeallocates it.Appendappends elements to a heap slice, growing if needed.Extendappends another slice to a heap slice, growing if needed.Clonecreates a shallow copy of the slice.Equalreports whether two slices are equal.ContainsandIndexsearch for value in a slice.Min,MinFunc,MaxandMaxFuncreturn the minimum/maximum element.Sort,SortFuncandSortStableFuncsort slices.
Conversions between numbers and strings. Offers an API similar to Go's strconv package, but with fewer features.
ParseBoolandFormatBoolconvert bool ↔ string.Atoi,Itoa,ParseIntandFormatIntconvert signed integer ↔ string.ParseUintandFormatUintconvert unsigned integer ↔ string.ParseFloatandFormatFloatconvert float ↔ string.
String operations. Offers an API similar to Go's strings package, but with fewer features.
Functions:
Clonereturns a fresh copy of a string.Comparecompares two strings lexicographically.ContainsandContainsFuncreport whether a substring is within a string.Countcounts the number of non-overlapping instances of a substring in a string.Cutslices a string around a separator.FieldsandFieldsFuncsplit a string around whitespace or a predicate.HasPrefixandHasSuffixreport whether a string begins/ends with a prefix/suffix.IndexandIndexFuncsearch for a substring within a string.Joinconcatenates string slices with a separator.Repeatreturns a string consisting of count copies of a string.ReplaceandReplaceAllreplace occurrences of a substring within a string.SplitandSplitNsplit a string into substrings.ToLowerandToUpperreturn a copy with all letters lowercased/uppercased.Trim,TrimFuncandTrimSpacetrim characters from a string.TrimPrefixandTrimSuffixtrim a prefix/suffix from a string.
Types:
Builderefficiently builds a string, minimizing memory copying.Readerreads data from a string.
Measuring and displaying time. Offers an API similar to Go's time package, but handles locations, formatting, and parsing differently.
Time is always stored as UTC internally. Formatting and parsing use C strftime/strptime verbs (e.g. %Y-%m-%d %H:%M:%S).
Constants:
UTC- zero offset (UTC).Nanosecond,Microsecond,Millisecond,Second,Minute,Hour- common durations.
Functions:
Nowreturns the current time in UTC (with monotonic clock reading).Datereturns the Time for a given year, month, day, hour, min, sec, nsec, and offset (seconds east of UTC).Unix,UnixMilli,UnixMicrocreate a Time from a Unix timestamp.SinceandUntilreturn the duration elapsed since or until a given time.Parseparses a time string per layout (strptime verbs) with a given offset, returning a Time.
Types:
Timerepresents an instant in time with nanosecond precision. Always UTC.Durationrepresents elapsed time as an int64 nanosecond count.CalDateis a date specified by year, month, and day.CalClockis a time of day specified by hour, minute, and second.Offsetrepresents a fixed offset from UTC in seconds.
Data and functions to test certain properties of Unicode code points. Offers an API similar to Go's unicode package, but with fewer Unicode features (no support for graphic characters, punctuation, symbols, etc.).
IsDigit,IsLetterandIsSpacecheck for different character classes.IsLower,IsUpperandIsTitlecheck for character case.ToLower,ToUpperandToTitlechange the character case.
Functions to convert between runes and UTF-8 byte sequences. Offers the same API as Go's unicode/utf8 package.
DecodeRuneandDecodeRuneInStringunpacks a UTF-8-encoded rune from a byte slice or a string.EncodeRunewrites a UTF-8-encoded rune into a byte slice.RuneCountandRuneCountInStringreturn the number of runes in a byte slice or a string.ValidStringreports whether a string consists entirely of valid UTF-8-encoded runes.