Comments (9)
You can use min((level_filter as usize) + 1, Trace::Trace as usize) as LevelFilter
as LevelFilter
has #[repr(usize)]
to do this already.
I'm not sure this a common enough case that we need the crate, though.
from log.
Are you sure? All versions of Rust which I tried this on say that the cast from usize
to LevelFilter
is illegal1. Given that the representation is known you can still hack the equivalent of C++'s reinterpret_cast
, but...
Footnotes
-
I would provide a link to https://play.rust-lang.org, but it appears to be broken right now. ↩
from log.
This works: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1f583a914a1b153a80213f3cd78c8676 and it's safe only because of #[repr(usize)]
. However you have to make sure the value is valid, i.e. not bigger than 5/LevelFilter::Trace
, but the transmute itself is not UB.
from log.
Agreed, but it would still be nice not having to resort to unsafe
, even if it is factually safe.
from log.
Agreed, but it would still be nice not having to resort to
unsafe
, even if it is factually safe.
Not really, the compiler can't ensure you do 6 as LevelFilter
, which would be UB (5 is max valid value).
from log.
Agreed, but it would still be nice not having to resort to
unsafe
, even if it is factually safe.Not really, the compiler can't ensure you do
6 as LevelFilter
, which would be UB (5 is max valid value).
Yes, I know. I meant that with an API like TryFrom<usize>
or the ones I suggested in my initial post would remove the need for library users to use unsafe
code like the one you posted earlier.
from log.
Which brings us back to
I'm not sure this a common enough case that we need the crate, though.
from log.
I agree that some kind of increment/decrement on log levels and/or filters would be useful. It would also circumvent the stated reasons the other issues were rejected (#318, #460). Namely, it doesn't increase exposure of the underlying integer representation to users. It still does, however, expose the exact sequence of elements, e.g. adding a new level between two existing levels might break someone's code. I don't know if that is an issue.
from log.
It still does, however, expose the exact sequence of elements, e.g. adding a new level between two existing levels might break someone's code. I don't know if that is an issue.
The sequence is already exposed via the Iterator
returned by LevelFilter::iter
. A new feature for iterating over levels will thus at least not introduce this issue.
from log.
Related Issues (20)
- Is this possible to make a failable log facade ? HOT 2
- "event" name support? (appending a suffix to the default target instead of replacing it entirely) HOT 5
- Derive `Deserialize` for `Level` HOT 1
- How do I set log level in Windows (Powershell)? HOT 3
- Is it possible to group logs? HOT 2
- Add tests that check the line numbers HOT 2
- The design of kV is not concise enough, I have a simple suggestion. HOT 2
- Surprising error when using `enabled` method in logger HOT 4
- Setting the file/line shown in a log message HOT 8
- ANSI escape sequences - Code injection HOT 4
- Feature suggestion: fatal log level with fatal! macro HOT 3
- log crate catches Clion stop signal HOT 2
- Release a build with `kv` support HOT 4
- Add log level fatal/critical HOT 2
- feature request: support the `critical` level defined in the `wasi-logging` spec HOT 1
- Add `critical!` Log Level HOT 1
- Log timestamp not match my timezone. HOT 1
- Release 0.4.22 breaks --all-features CI testing HOT 10
- Custom log levels HOT 3
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 log.