StackOverflow when define new() method in 'impl ActiveModelBehavior for ActiveModel' #2807
Answered
by
tyt2y3
Charlestar
asked this question in
Q&A
-
|
Below is my code, when I define |
Beta Was this translation helpful? Give feedback.
Answered by
tyt2y3
Nov 12, 2025
Replies: 1 comment 2 replies
-
|
you can't call Default::default() inside new() as it calls back into itself hence causing stack overflow. impl ActiveModelBehavior for ActiveModel {
fn new() -> Self {
Self {
status: ActiveValue::Set(0),
create_time: ActiveValue::Set(chrono::Utc::now().into()),
modify_time: ActiveValue::Set(chrono::Utc::now().into()),
..ActiveModelTrait::default()
}
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Charlestar
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can't call Default::default() inside new() as it calls back into itself hence causing stack overflow.