Comments (2)
Better idea, no null pointer constant.
Instead we have a "maybe" type, perhaps by putting a question mark before another type, like this:
?*mut u8
This represents a tagged union which can either be None
or a *mut u8
which is guaranteed to not be null. You could .unwrap()
on a maybe type to resolve to a non-null type, or panic.
Also, a ??
operator which the left operand is a maybe type and the right operand is an expression which is of the unwrapped type. So you could for example:
fn func(x : ?bool) {
let want_the_thing = x ?? true;
}
Now you have an optional boolean that has a default value of true.
Or:
fn create_a_thing() -> error {
let thing = malloc(...) ?? {
return Error.OutOfMem;
};
things.append(thing);
return Error.None;
}
The right hand side of the ??
returned unreachable which is also legal.
from zig.
Alternate unpacking syntax ideas:
idea 1:
fn report_error(msg : string, maybe_additional_info : ?string) {
report(str);
ifunpack additional_info = maybe_additional_info {
report(additional_info);
}
}
idea 2:
fn report_error(msg : string, maybe_additional_info : ?string) {
report(str);
if let additional_info ?= maybe_additional_info {
report(additional_info);
}
}
from zig.
Related Issues (20)
- cImport does not normalize early return
- zig build and socks5 proxy issues
- overflow error when linking big libraries on MacOS HOT 3
- Union comptime var compiler crash HOT 1
- Assertion failure in LLVM backend computing x86_64 calling convention ABI in lowerSystemVFnRetTy
- std.posix.accept: improve EINVAL's error name from SocketNotListening to SocketOrAddrLenIncorrect. HOT 1
- Panic in ziglang/zig/src/link/MachO/Dylib.zig:513:48
- Compile error using `unusedCapacitySlice` with `ArrayListAligned` if alignment > 1
- package manager: `zig fetch --save <url>` overwrites `.lazy` field
- zig build test hangs in Sema beginning in 0.12.0-dev.3676+21a6a1b0f HOT 4
- On a mounted VHD without a drive letter: `error: unable to find zig self exe path: FileNotFound` HOT 12
- `--release=x` ignored when `preferred_optimize_mode` is set HOT 3
- Compiler crashes when taking slice with undefined end index HOT 1
- std.compress.deflate fails on particular input HOT 3
- The file generated by running 'build' consumes more memory than 'zig build run' HOT 2
- Compile error when `side_channels_mitigations = .none`
- Broken .dll exported functions when libCpp is linked
- destructuring problem HOT 5
- zig fetch error: unrecognized 'Content-Type' header: 'application/zip' HOT 2
- Zig 0.12.0 fails to link against dynamic library on MacOS HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zig.