fixed generics
This commit is contained in:
@@ -24,7 +24,7 @@ pub trait DataProvider {
|
||||
}
|
||||
|
||||
/// Get display value (for password masking, etc.) - optional
|
||||
fn display_value(&self, index: usize) -> Option<&str> {
|
||||
fn display_value(&self, _index: usize) -> Option<&str> {
|
||||
None // Default: use actual value
|
||||
}
|
||||
}
|
||||
@@ -32,16 +32,13 @@ pub trait DataProvider {
|
||||
/// Optional: User implements this for autocomplete data
|
||||
#[async_trait]
|
||||
pub trait AutocompleteProvider {
|
||||
type SuggestionData: Clone + Send + 'static;
|
||||
|
||||
/// Fetch autocomplete suggestions (user's business logic)
|
||||
async fn fetch_suggestions(&mut self, field_index: usize, query: &str)
|
||||
-> Result<Vec<SuggestionItem<Self::SuggestionData>>>;
|
||||
-> Result<Vec<SuggestionItem>>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SuggestionItem<T> {
|
||||
pub data: T,
|
||||
pub struct SuggestionItem {
|
||||
pub display_text: String,
|
||||
pub value_to_store: String,
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ pub struct FormEditor<D: DataProvider> {
|
||||
data_provider: D,
|
||||
|
||||
// Autocomplete suggestions (library manages UI, user provides data)
|
||||
pub(crate) suggestions: Vec<SuggestionItem<String>>,
|
||||
pub(crate) suggestions: Vec<SuggestionItem>,
|
||||
}
|
||||
|
||||
impl<D: DataProvider> FormEditor<D> {
|
||||
@@ -72,7 +72,7 @@ impl<D: DataProvider> FormEditor<D> {
|
||||
}
|
||||
|
||||
/// Get autocomplete suggestions for rendering (read-only)
|
||||
pub fn suggestions(&self) -> &[SuggestionItem<String>] {
|
||||
pub fn suggestions(&self) -> &[SuggestionItem] {
|
||||
&self.suggestions
|
||||
}
|
||||
|
||||
@@ -161,7 +161,6 @@ impl<D: DataProvider> FormEditor<D> {
|
||||
pub async fn trigger_autocomplete<A>(&mut self, provider: &mut A) -> Result<()>
|
||||
where
|
||||
A: AutocompleteProvider,
|
||||
A::SuggestionData: std::fmt::Debug, // Change from Display to Debug
|
||||
{
|
||||
let field_index = self.ui_state.current_field;
|
||||
|
||||
@@ -172,18 +171,9 @@ impl<D: DataProvider> FormEditor<D> {
|
||||
// Activate autocomplete UI
|
||||
self.ui_state.activate_autocomplete(field_index);
|
||||
|
||||
// Fetch suggestions from user
|
||||
// Fetch suggestions from user (no conversion needed!)
|
||||
let query = self.current_text();
|
||||
let suggestions = provider.fetch_suggestions(field_index, query).await?;
|
||||
|
||||
// Convert to library's format (could be avoided with better generics)
|
||||
self.suggestions = suggestions.into_iter()
|
||||
.map(|item| SuggestionItem {
|
||||
data: format!("{:?}", item.data), // Use Debug formatting instead
|
||||
display_text: item.display_text,
|
||||
value_to_store: item.value_to_store,
|
||||
})
|
||||
.collect();
|
||||
self.suggestions = provider.fetch_suggestions(field_index, query).await?;
|
||||
|
||||
// Update UI state
|
||||
self.ui_state.autocomplete.is_loading = false;
|
||||
|
||||
Reference in New Issue
Block a user