must
Version, currently 0.1.02 versions
- 0.2.0latestJan 27, 2020
- 0.1.0not indexedJan 27, 2020
github.com/maiha/must.cr
Library for dynamic typing in Crystal
Nothing has been indexed for 0.1.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
must:
github: maiha/must.cr
version: ~> 0.1.0Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.0. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
must.cr 
Library for dynamic typing in Crystal.
Core class pollution
Object#must
Features
- Checking Types : Dynamically guarantee object types
- Casting Types : Dynamically cast object types
- Matching Features : Object matching and data extraction
# checking
1.must(Int32) # => 1
1.must(Bool) # raises Must::TypeError
# casting
1.must.cast(String) # => "1"
1.must.cast(Bool) # raises Must::CastError
# matching
708.must.match(/0/) # => 708
708.must.match(/0(.)/, "$1") # => "8"
- crystal: 0.31.1
Why not use as for casting?
aschecks types at compile timemustchecks type at runtime
json = JSON.parse(%|{"a": 1}|)
json["a"].as_f # Unhandled exception: cast from Int64 to Float64 failed (runtime)
json["a"].raw.to_f # undefined method 'to_f' for Array(JSON::Any) (compile time)
json["a"].raw.must.cast(Float64) # => 1.0
Installation
- Add the dependency to your
shard.yml:
dependencies:
must:
github: maiha/must
version: 0.2.0
- Run
shards install
Usage
require "must"
API
any?, any
Checks empty? or not. It returns true if the class doesn't have empty? method.
1.must.any? # => true
1.must.any # => 1
Set(Int32).new.any? # => false
"".must.any? # => false
"".must.any # raises Must::Error("(value) is empty")
"".must.any(name: "foo") # raises Must::Error("foo is empty")
Development
Contributing
- Fork it (https://github.com/maiha/must.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- maiha - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.0- Tagged
- Jan 27, 2020
- Commit
1d51a541177f- Indexed
- not yet
Dependents
Repository
github.com/maiha/must.cr
Metadata
- Created
- Aug 19, 2026
- Updated
- Nov 12, 2026
- Synced
- Nov 12, 2026
- Versions
- 2