Я смог сделать это ночью, используя функцию const, возвращающую закрытие:
#![feature(const_fn)]
fn foo(x: String, y: String) -> String {
x + &y
}
const fn foo_applied(x: String) -> impl Fn(String) -> String {
move |y| foo(x.clone(), y)
}
fn main() {
let foo_1 = foo_applied("1 ".into());
println!("{}", foo_1("2".into()));
let foo_2 = foo_applied("2 ".into());
println!("{}", foo_2("1".into()));
}
Это не делает, кажется, "из поля" решение для этой вещи.
Взятый от Старый Joel На Форумах программного обеспечения
Так или иначе.. помещать эту тему для отдыха.. следующее было моим решением VB6: Я определяю 2 символа в своем проекте VB "MPDEBUG" и "MPRELEASE" и вызываю следующую функцию как первую операцию в моей функции точки входа приложений.
Public Sub ChangeDirToApp()
#If MPDEBUG = 0 And MPRELEASE = 1 Then
' assume that in final release builds the current dir will be the location
' of where the .exe was installed; paths are relative to the install dir
ChDrive App.path
ChDir App.path
#Else
' in all debug/IDE related builds, we need to switch to the "bin" dir
ChDrive App.path
ChDir App.path & BackSlash(App.path) & "..\bin"
#End If
End Sub
"Текущий каталог, кажется, dir VB6" только при открытии проекта, использующего Открытый для файла.
Открытый это путем двойного щелчка по .vbp файлу при закрытии IDE.
Решение, что я нашел, что работы используют Sub Main
и проверяют, работает ли программа в IDE.
Dim gISIDE as Boolean
Sub Main()
If IsIDE Then
ChDrive App.Path
ChDir App.Path
End If
' The rest of the code goes here...
End Sub
Public Function IsIDE() As Boolean '
IsIDE = False
'This line is only executed if running in the IDE and then returns True
Debug.Assert CheckIDE
If gISIDE Then
IsIDE = True
End If
End Function
Private Function CheckIDE() As Boolean ' this is a helper function for Public Function IsIDE()
gISIDE = True 'set global flag
CheckIDE = True
End Function
'Declaration
Private Declare Function SetCurrentDirectory Lib "kernel32" _
Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
'syntax to set current dir
SetCurrentDirectory App.Path
Текущий каталог для любой программы - включая vb6 - может быть изменен в свойствах ярлыка. Я изменил его на корень моего исходного дерева, это делает использование Открытым для файла более быстрый.