Conversation
|
Sorry, missed the workspace tests locally. Marking as draft until I fix those |
88a7447 to
0274b22
Compare
|
Potential optimization idea for the future:
This is entirely backwards-compatible and can be done later in |
| //! impl IdenStatic for MyFunction { | ||
| //! fn as_str(&self) -> &'static str { |
There was a problem hiding this comment.
can you keep the example in README using impl Iden?
| #[cfg(not(feature = "thread-safe"))] | ||
| /// Identifier statically known at compile-time. | ||
| pub trait IdenStatic: Iden + Copy + 'static { | ||
| fn as_str(&self) -> &'static str; |
There was a problem hiding this comment.
The reason IdenStatic has extra Copy and 'static requirements is because of SeaORM. but right now SeaORM has it's own IdenStatic trait and not actually using this. if possible (without orphan rule constraint), we should reuse this trait in SeaORM
There was a problem hiding this comment.
I am fine with this breaking change as this only affects users who implemented Iden manually
However, I'd like to clarify do we still recommend impl Iden for users with existing impl Iden? IdenStatic is not a full replacement of Iden, if users need to choose between Iden / IdenStatic, can you add some docs regarding this in readme?
Before or after merging this, can you prepare changes needed in SeaORM as well?
| impl IdenStatic for Character { | ||
| fn as_str(&self) -> &'static str { |
There was a problem hiding this comment.
this is equivalent to the following right?
impl Iden for Character {
fn unquoted(&self) -> Cow<'static, str> {
match self {
Self::Table => "character",
Self::Id => "id",
Self::Character => "character",
Self::FontSize => "font_size",
Self::SizeW => "size_w",
Self::SizeH => "size_h",
Self::FontId => "font_id",
Self::Ascii => "ascii",
Self::CreatedAt => "created_at",
Self::UserData => "user_data",
}.into()
}
}if so we should at least keep one
There was a problem hiding this comment.
Apart from not implementing IdenStatic, this is equivalent, yes. I used IdenStatic where possible because it's less verbose and conveys more information in the type system.
If you want to keep a direct impl Iden somewhere in the docs/examples, I'd choose an example that makes sense (a runtime-allocated, non-static identifier). We have a few such synthetic examples in trybuild tests
Not exactly. I also removed
Why? Any
Ok, I'll add this a bit later.
Yeah, makes sense to check such breaking changes before merging. |
that's what I want to clarify. keep doing the confusion is that sea-orm has it's own |
|
Ok, I'll try to unify those when I prepare SeaORM |
I was very suprised and confused when I noticed the following in the codebase:
Iden::quoted, saying that it doesn't actually return a quoted string (!). In fact, the quoting is done later by the (DB-specific) backend.fn is_static_identhat's not actually about knowing the identifier at compile time. In fact, it's about having special characters in the identifier (and the need to escape the identifier in the backend).Cow::Ownedto indicate the presense of special characters (rather than to simply store a runtime-provided string).It's so weird and non-obvious.
Here, I streamline things:
Removed the
Iden::quotedmethod that isn't actually quoted.I understand that this is a breaking change. But if the users can't actually get a properly-quoted string without a specific DB backend, then we should help them notice this reality.
Made
Iden::unquotedreturn aCow, as that's the method that actually constructs aDynIden(Cow).This is a breaking change.
Replaced
IdenStatic: Idenwithimpl<T> Iden for T where T: IdenStatic.Technically a breaking change for manual implementors, but most people probably use derives.
Removed all other extra supertraits from
IdenStatic. All tests pass without those, and it's not clear why those were needed. Those are probably leftowers from the oldIdensystem. If those are actually needed, we should test and document that.Technically a breaking change, although I doubt that many people worked with generic
IdenStaticand relied on those implied bounds.Replaced
impl Idenwithimpl IdenStaticeverywhere where the string is static (e.g., in all derives).Removed unnecessary allocations of
Cow::Owned.Removed
is_static_iden.This isn't a breaking change because we didn't have that in
1.1.x.Updated the docs.
To be fair, I understand the intended meaning and benefit of
is_static_idenand indicating it withCow::Borrowed. When we know at compile time that the identifier doesn't have any special characters, the backend canwrite_strit as-is, in one go. Because that's no longer the case, my PR may regress the performance a little.However:
Cow::Borrowedonly when the string doesn't have special characters. It's easy to chooseCow::Borrowedsimply because you have a static string (whether or not it contains special characters). That's the most obvious thing to do.Cow::Borrowedmore often.write_strpath in the backend, we can put theis_static_idencheck right there before the write. But I wouldn't worry about that.The main thing that I'm going for here is conceptual clarity, rather than performance:
IdenStatic.qoutedthat isn't actually quoted.falsefromis_static_iden.