stringToBytes converts string to []byte without allocation. This is the Go equivalent of Rust's str.as_bytes() - a zero-cost reinterpret cast. The returned slice MUST NOT be modified (same as Rust's immutable &[u8]). go:inline
(s string)
| 61 | // |
| 62 | //go:inline |
| 63 | func stringToBytes(s string) []byte { |
| 64 | if s == "" { |
| 65 | return nil |
| 66 | } |
| 67 | // G103: Safe - read-only view of immutable string data (like Rust's as_bytes) |
| 68 | return unsafe.Slice(unsafe.StringData(s), len(s)) //nolint:gosec |
| 69 | } |
| 70 | |
| 71 | // Regex represents a compiled regular expression. |
| 72 | // |
no outgoing calls
no test coverage detected