Skip to content

Nlopt::srand_seed cannot be invoked #16

@adwhit

Description

@adwhit

Nlopt::srand_seed cannot be directly invoked, because of the requirements of Nlopt

1168 |         Nlopt::srand_seed(Some(10));
     |         ^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `F` declared on the struct `Nlopt`

If we try to name the objective fn:

error[E0747]: constant provided when a type was expected
    --> src/lib.rs:1168:17
     |
1168 |         Nlopt::<fake_objfn, ()>::srand_seed(Some(10));
     |                 ^^^^^^^^^^
     |
     = help: `fake_objfn` is a function item, not a type
     = help: function item types cannot be named directly

A hack that does work:

        fn fake_objfn(_: &[f64], _: Option<&mut [f64]>, _: &mut ()) -> f64 {
            unreachable!()
        }

        fn set_seed<F: ObjFn<()>>(_: F) {
            Nlopt::<F, ()>::srand_seed(Some(10));
        }
        set_seed(fake_objfn);

Yuck! It should probably just be a global function (not tied to the Nlopt object), like in the C lib.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions